Position of <script> tags #38

Closed
wturrell opened this Issue Aug 10, 2012 · 2 comments

Comments

Projects
None yet
2 participants
Contributor

wturrell commented Aug 10, 2012

I assume it's compulsory that the calls to picturefill and matchmedia go at the top of the document, before the images load, and can't be shunted to above the closing </body> tag?

Could you add something on this to the README?

Contributor

wturrell commented Aug 15, 2012

Having thought about it a bit more, I've concluded it doesn't/shouldn't matter at all - there are no image tags (apart from the noscript) in the DOM until picturefill runs, so there's nothing for the browser to load until it as, therefore no possibility of unintentionally loading more than one size of the image. So you can combine and minify picturefill with all your other code.

The only issue I can see is if you have some special javascript that needs to act on the images once the page is displayed - you'd need to call/include that after picturefill.js to be certain they existed.

Owner

scottjehl commented Aug 15, 2012

Picturefill is only meant for images that need negotiation - not all img elements on a page.

Anyway, no there's no restriction to where you load it. It runs on domcontentloaded and window unload as a fallback.

On Aug 15, 2012, at 3:18 PM, William Turrell wrote:

Having thought about it a bit more, I've concluded it doesn't/shouldn't matter at all - there are no image tags (apart from the noscript) in the DOM until picturefill runs, so there's nothing for the browser to load until it as, therefore no possibility of unintentionally loading more than one size of the image. So you can combine and minify picturefill with all your other code.

The only issue I can see is if you have some special javascript that needs to act on the images once the page is displayed - you'd need to call/include that after picturefill.js to be certain they existed.


Reply to this email directly or view it on GitHub.

scottjehl closed this Feb 28, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment