简体   繁体   中英

Is Modernizr.load (Yepnope) meant to be used in the <head>

由于Modernizr.loadYepnope是异步加载程序,因此在<head>或页面末尾使用它们是否在性能上更好?

It depends on the resources being loaded. See this thread where Yepnope developer Alex Sexton says to combine all the resources into one call to the loader. In practice, if any of the resources you want to load with Modernizr.load or Yepnope affect what the user sees or needs when the page first loads, then IMO in most cases you want to call the loader after your critical resources but still in the <head> .

Comment from yeapnope developer:

It's better at the end of the page, right before the closing </body> .

I think it is better to load them in the bottom page.

Modernizer and Yepnope need first be loaded in the page to load other scripts. So, when you add the <script src="modernizer.js"> you are blocking the rendering time in the browser. That happens because the browser stop all rendering while the script is downloading, compiling and executing.

As yahoo and google says defer loading scripts is always good.

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