Preventing Images being cached in the browser

前端 未结 2 930
独厮守ぢ
独厮守ぢ 2021-01-28 09:56

I have a feature of \"Browse Pictures\" where there are thumbnails and when a user clicks it expands.

Now, both these images are stored in separate virtual directories w

相关标签:
2条回答
  • 2021-01-28 10:19

    It sounds like you don't want to prevent them from being cached as such, but you want to give them different URLs.

    If they do have different URLs, then this is not a caching problem.

    To prevent caching, you use a cache-control:no-cache HTTP response header when serving the images. (are you using Apache?)

    But if you really prevent caching, your data transfer will be higher than it needs to be, every time they visit your gallery, they will be fetching your images.

    0 讨论(0)
  • 2021-01-28 10:43

    You can add a random URL parameter to the image's href, so that the HTML rendered looks like

    <img src="http://static.example.com/some/large/image.jpg?234234652346"/>
    

    instead of

    <img src="http://static.example.com/some/large/image.jpg"/>
    
    0 讨论(0)
提交回复
热议问题