Move the javascript to the bottom of the document Move the javascript to the bottom of the document
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Move the javascript to the bottom of the document

Started by papukaija, June 10, 2010, 09:37:48 AM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

papukaija

According to Google's and Yahoo!'s speed tips, all javascript code should be put at the bottom of the documenent (just before the closing body tag). An interactive demo is available here comparing the difference between the javascript at the top and bottom of a document. With jquery the loading time difference should be lower than in the demo, but still the javascript's place is at the bottom of the document.

Joachim Müller

The documentation doesn't have to be optimized for speed, as it meant to be used by the admin of the gallery, preferably using a local copy of the docs. The jquery script will be cashed anyway. As it's not important to speed the docs up in this aspect, they will remain the traditional way, with the JavaScript calls inside between <head> and </head> (sorry, I'm a purist in this aspect).
I guess though that you're not refering to the documentation, but to the output generated by Coppermine. I can see the point here, but then the speed penalty for loading the jquery library in the head is neglible imo. The big performance win in the speed tips is if you move big chunks of inline JS from the head to the end of the document, which is something we hardly do. . As suggested above, I'm not fond to add JS at the bottom inside the body.
Thanks for the suggestion though.

Αndré

Quote from: Joachim Müller on June 10, 2010, 01:00:07 PM
I guess though that you're not refering to the documentation, but to the output generated by Coppermine.
That's what I've understood :)

Timos-Welt

I just contributed a little plugin to the SVN (http://coppermine.svn.sourceforge.net/viewvc/coppermine/branches/cpg1.5.x/plugins/js_to_bottom.tar.gz?view=tar) to get what papukaija probably wants.

papukaija: Please test the plugin and report if it works for you and if it improves your page access times. On my gallery, it makes the pages usable ~ 3-4 seconds earlier at first time visits.

papukaija

Quote from: Joachim Müller on June 10, 2010, 01:00:07 PM
I guess though that you're not refering to the documentation, but to the output generated by Coppermine.
Quote from: Αndré on June 10, 2010, 03:18:28 PM
That's what I've understood :)
Yes, I'm referring to the output generated by Coppermine.

I'll test the plugin tomorrow.


Timos-Welt

No it doesn't.
http://www.sk-foto.info/thumbnails-lastup.html
produces errors because of the jquery framework coming too late for some inline scripts. I think I'll have to drop the plugin and include the mechanism to my jsmin plugin, leaving the basic scripts always in the head and only moving additional scripts to the bottom of the page. I've done this here and everything seems to work fine.

taucher_0815

When I try to open the URL you mentioned, i receive a normal output...

taucher_0815

Same for Chrome and Safari after clearing all caches

Timos-Welt

Try IE, or watch the error console of your browsers and you'll see what I mean.

taucher_0815

OK, got it...

Plugin is now uninstalled and reporting no more errors.

Thanks for the hint

papukaija

Quote from: Timos-Welt on June 10, 2010, 03:19:24 PM
papukaija: Please test the plugin and report if it works for you and if it improves your page access times. On my gallery, it makes the pages usable ~ 3-4 seconds earlier at first time visits.
With this plugin, the index.php loads 2 -5 seconds faster than without it when the browser's cache is disabled. When the cache is enabled, the difference is about 5 seconds, but only on the first load, after that, the difference is at maximum 0,5 second. I tested this on my local lamp (in FF with Firebug extension). I also noticed that the error console displays many javascript errors.