redis預(yù)加載數(shù)據(jù)的方法:1.使用CSS實(shí)現(xiàn)預(yù)加載。2.增加JS代碼來推遲預(yù)加載的時(shí)間。
使用CSS實(shí)現(xiàn)預(yù)加載,例如:
#preload-01 { background: url(http://domain.tld/image-01.png) no-repeat -9999px -9999px; }#preload-02 { background: url(http://domain.tld/image-02.png) no-repeat -9999px -9999px; }
#preload-03 { background: url(http://domain.tld/image-03.png) no-repeat -9999px -9999px; }
增加JS代碼來推遲預(yù)加載的時(shí)間:
function preloader() {
if (document.getElementById) {
document.getElementById("preload-01").style.background =
"url(http://domain.tld/image-01.png) no-repeat -9999px -9999px";
document.getElementById("preload-02").style.background =
"url(http://domain.tld/image-02.png) no-repeat -9999px -9999px";
document.getElementById("preload-03").style.background =
"url(http://domain.tld/image-03.png) no-repeat -9999px -9999px";
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(preloader);