Disable cache for some images

前端 未结 13 1119

I generate some images using a PHP lib.

Sometimes the browser does not load the new generated file.

How can I disable cache just for images created dynamica

相关标签:
13条回答
  • 2020-11-22 08:28

    If you have a hardcoded image URL, for example: http://example.com/image.jpg you can use php to add headers to your image.

    First you will have to make apache process your jpg as php. See here: Is it possible to execute PHP with extension file.php.jpg?

    Load the image (imagecreatefromjpeg) from file then add the headers from previous answers. Use php function header to add the headers.

    Then output the image with the imagejpeg function.

    Please notice that it's very insecure to let php process jpg images. Also please be aware I haven't tested this solution so it is up to you to make it work.

    0 讨论(0)
提交回复
热议问题