简体   繁体   中英

If image is already in cache, will using a preloading technique be harmful to load time?

I'm using this technique (mentioned in the comment) for preloading large header images.

The definitive best way to preload images using JavaScript/jQuery?

The upshot is that it calls for loading all of the images in a hidden div on my homepage. If the user hits my homepage multiple times, will these images be pulled from the cache, or will they be "reloaded" if you will from the server?

What I tried
I attempted something like:

if(!isset($_SERVER['imgLoaded'])) {
    // preload images
    $_SERVER['imgLoaded'] == 1;
}

but it didn't seem to work. (yes, I called session_start() before any headers were sent; Session is working fine.

Assuming your web server sends appropriate http headers to inform the browser the images are safe to cache, yes, its very likely the browser won't repeat http requests unless a refresh is forced.

Here's good info http://www.mnot.net/cache_docs/

I'm not sure why you posted php code...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM