资源预加载能够提高用户体验,若是每次用户打开页面都要加载图片,js,css等资源,会影响用户体验。资源预加载能够必定程度上改善这种状况。javascript
咱们能够作的是,但第一个页面load完的时候,在用户阅读网页的空隙,把下一个页面所用的资源提早加载过来cache住,这样下个页面就直接读缓存资源了,这样能够必定程度改善用户体验。php
那么预加载资源须要解决的主要问题是JS加载过来不会被直接执行,css加载过来不会更改页面样式。css
这样就会产生不少方案, 这里介绍一种不错的兼容方案:java
1. IE下用new Image()来加载浏览器
2. 其他浏览器使用object元素来加载缓存
缘由app
new Image().src
doesn't do the job in FF because it has a separate cache for images. Didn't seem to work in Safari either where CSS and JS were requested on the second page where they sould've been cachedobject
element has to be outside the head
in most browsers in order to fire off the downloadsobject
works also in IE7,8 with a few tweaks (commented out in the code above) but not in IE6. In a separate tests I've also found the object element to be expensive in IE in general.【程序源码】ide
【相关连接】post
http://www.phpied.com/preload-cssjavascript-without-execution/spa
http://www.phpied.com/the-art-and-craft-of-postload-preloads/
http://headjs.com/