Lazy loading JavaScript and Inline JavaScript

后端 未结 7 1478
悲哀的现实
悲哀的现实 2020-12-29 07:31

I noticed in the of my site (for work), there are a lot of and <

7条回答
  •  醉话见心
    2020-12-29 07:46

    You can actually lazyload inline javascript: 1- Change the type parameter in the inline script to: text/delayscript

    FROM

        
    
    

    To

        
    
    

    Giving the script tag a custom Mime type text/delayscript forces the browser to ignore its content (Please note that leaving it out entirely will default to text/javascript).

    2- Lazy load all inline scripts Once heads.js (Or an other framework you might be using) confirms that it lazy loaded all your external JS, you can then grab the content of all your custom script tags and inject them in the page:

    
    
                                     
                  
提交回复
热议问题