Jump to content

Javascript load order..


26985

Recommended Posts

Hi everyone,Simple request: http://www.constantincerdan.com/Choose a category under 'Work' and notice that my site loads all the images first before the javascript, which then snaps everything closed under their respective headers.I've asked in the Wordpress forums if there is a way to change this so that it loads the script first rather than the images but nobody seems to know, although I'm sure there must be..Just want to know if it's possible and if so how to do it?Thanks in advance!

Link to comment
Share on other sites

The simple way is to put the <script> tag right at the end of the body.The other way is to make DOMContentLoaded event workarounds for all browsers and execute the code when the event fires.

Link to comment
Share on other sites

The problem is, all the elements that need to be targeted to apply this accordion effect, need to be present/rendered to assign this effect, and the images are within these targeted elements, and because the images are quite large, you will see them as page loads and js kicks in.The only possible way is to store images link ref in js array, leave src of img tags empty or link to small size blank image, and populate the img src link afterwards.edit:OR without using array (because of matching stored image path with correct img tag), but still using blank image, add img link ref temporary to title (now! i don't know if wp adds the title attribute, using alt text), then on page load, transfer title text to img src, copy alt text to title (or vice versa, if possible) and you are good to go, if js enabled of course.

Link to comment
Share on other sites

Thanks for both of your replies. It's much appreciatedI tried Ingolme's recommendation first and just put the <script> at the end of <body> and that seems to have fixed the problem. Thank you. I'm surprised that the solution was so simple and yet nobody else seemed to know how to do it. Also, seeing as it is, as you said yourself, a simple way to do it, are there any downsides to doing it this way?

Link to comment
Share on other sites

Thanks for both of your replies. It's much appreciatedI tried Ingolme's recommendation first and just put the <script> at the end of <body> and that seems to have fixed the problem. Thank you. I'm surprised that the solution was so simple and yet nobody else seemed to know how to do it. Also, seeing as it is, as you said yourself, a simple way to do it, are there any downsides to doing it this way?
Not really, but I like keeping all my scripts in the <head> section to fully separate the content from the behaviour.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...