Preload script without execute

前端 未结 6 1871
生来不讨喜
生来不讨喜 2020-12-06 17:09

Problem

In order to improve the page performance I need to preload scripts that I will need to run on the bottom page.

I

6条回答
  •  生来不讨喜
    2020-12-06 17:26

    With similar technique you may preload scripts and stylesheets using img for Internet Explorer and object tag for every other browser.

    var isMSIE = /*@cc_on!@*/false;
    
    var resources = ['a.js', 'b.js', 'c.css'];
    
    for (var i=0; i

    There is a blog post describing such a technique and outlining caveats: Preload CSS/JavaScript without execution.

    But why don't you want to just use dynamically added scripts just like suggested in other answer, this will probably lead to a cleaner solution with more control.

提交回复
热议问题