2

Here is my preload script:

<script type="text/javascript"> 
Image_1 = new Image(1,1);
Image_1.src = "images/sprites.png";
</script>

And it works fine. I can see in the headers the image loading.

Here's my question. Even though I have preloaded sprites.png, I notice that when I go to a page on my site that simply displays that entire image, the headers tell me my browser is requesting the server to send the image again.

I'm hoping to not sound too naive. But, why would the browser request the image when I preloaded it earlier? Are there other reasons the browser would need to re-request?

Also, I put the dimensions as Image(1,1). Sometimes I don't know the dimensions, as that image gets updated from time to time. Maybe that's a reason?

4

1 回答 1

1

您需要从服务器发送带有图像的 Expires 标头,以在浏览器中启用缓存。

例如在 Apache 中(在 .htaccess 中)

启用过期:

ExpiresActive On

按日期:

ExpiresDefault "access plus 30 days"

或按文件类型:

ExpiresByType image/gif "modification plus 5 hours 3 minutes"
于 2010-04-12T23:55:28.320 回答