Quick question regarding CSS sprites and memory usage

后端 未结 3 854
太阳男子
太阳男子 2021-02-07 10:09

Well, it\'s more to do with images and memory in general. If I use the same image multiple times on a page, will each image be consolidated in memory? Or will each image use a

3条回答
  •  悲哀的现实
    2021-02-07 10:49

    Webbrowsers identifies cacheable resources by their ETag response header. If it is absent or differs among requests, then the image may be downloaded and stored in cache multiple times. If you (actually, the webserver) supply an unique and the same ETag header for each unique resource, then any decent webbrowser is smart enough to keep one in cache and reuse it as long as its Expires header allows.

    Any decent webserver will supply the ETag header automatically for static resources, it is often autogenerated based on a combination of the local filename, the file length and the last modified timestamp. But often they don't add the Expires header, so you need to add it yourself. After judging your post history here at Stackoverflow I safely assume that you're familiar with Apache HTTPD as web server, so I'd suggest to have a look at mod_expires documentation to learn how to configure it yourself to an optimum.

    In a nutshell, serve the sprite image along with an ETag and a far future Expires header and it'll be okay.

提交回复
热议问题