[Pro] Javascript in head or before /body?

In my search to optimise a FW produced site (and maybe hand it over to another developer) I thought about positioning of Javascript on the page. I realise that some scripts controlling should be loaded first. But since the browser cannot load more than two requests at the time, the rest of the page is waiting. http://stackoverflow.com/a/13240969

How to decide what comes in head, and what could be better before /body? One hopes that the browser caches scripts that are used all over the web.

I see a lot of pages with all the script loaded latest.

I found this http://headjs.com/

Any of you familiar with it?
Is it useful, or just another extra overload?


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Apr 10, 2013, at 3:36 AM, atelier wrote:

I found this http://headjs.com/

Any of you familiar with it?
Is it useful, or just another extra overload?

It looks interesting. Give it a try. It does seem to be tightly coupled with jQuery in places, not sure how deep that goes. It may just be them paving the cowpaths.

Generally, the stuff loaded from a CDN will be cached for a really long time, so you don’t need to worry about it much more than the total number of requests after the first visit, and you won’t necessarily be the site that loads it first, either. I’m not convinced that a Yahoo-style load just before the closing /body is any slower than this technique.

Watch out for timing issues, for scripts that need to run before the page appears. Carousel 2, which uses Prototype.js’s document.observe(‘dom:loaded’) callback, will be particularly unhappy about you doing this, because it completely re-arranges the page before it is visible, so you could have a “flash of unstyled content” if you go down this route. (I haven’t tried it there, I just know that waiting to paint the screen until the JavaScript has loaded is a feature in that particular case, not a bug.)

Walter


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Allright, i’ll check it out. Could be useful for my learning curve :wink:


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options