js 预加载

01.window.onload = function() {

02.

03.    setTimeout(function() {

04.       

05.// reference to <head>

06.        var head = document.getElementsByTagName('head')[0];

07.

08.        

09.// a new CSS

10.        var css = document.createElement('link');

11.        css.type = "text/css";

12.        css.rel  = "stylesheet";

13.        css.href = "http://domain.tld/preload.css";

14.        

15.// a new JS

16.        var js  = document.createElement("script");

17.        js.type = "text/javascript";

18.        js.src  = "http://domain.tld/preload.js";

19.        

20.// preload JS and CSS

21.        head.appendChild(css);

22.        head.appendChild(js);

23.         

24.// preload image

25.        new Image().src = "http://domain.tld/preload.png";

26.

27.    }, 1000);

28.

29.};

 

posted @ 2015-10-01 19:31  yangxu6069  阅读(701)  评论(0编辑  收藏  举报