简体   繁体   中英

How to precompile picturefill with rails asset pipeline

I'm using the polyfill picturefill to add support for the img attributes srcset and sizes in browsers like IE. This polyfill doesn't work when precompiling the javascript in the asset pipeline in rails. It DOES work when I exclude it from the pipeline and include it (picturefill) at the end of my <body> tag.

My guess is that picturefill gets executed before the page has fully been loaded (with all 'img' tags). Is this correct? And if so, why didn't the authors add something like a document.ready() event? Is there a way I can solve this more elegant than including the whole script at the end of my body? Adding the script like this seems like a huge performance hit.

I found a solution, http://reed.github.io/turbolinks-compatibility/picturefill.html

it looks like turbolinks creates a page:load event, and we can use that event to call the picturefill script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM