TheFilmGod Posted June 22, 2008 Share Posted June 22, 2008 Will images cache in the browser if they are called by absolute linking? i.e. http://www.mydomain.com/someimage.jpg instead of someimage.jpg? Quote Link to comment https://forums.phpfreaks.com/topic/111345-will-images-cache-when-called-absolutely/ Share on other sites More sharing options...
Daniel0 Posted June 22, 2008 Share Posted June 22, 2008 Depends on your browser settings and the headers sent by the server. Quote Link to comment https://forums.phpfreaks.com/topic/111345-will-images-cache-when-called-absolutely/#findComment-571634 Share on other sites More sharing options...
TheFilmGod Posted June 22, 2008 Author Share Posted June 22, 2008 Depends on your browser settings and the headers sent by the server. I can't control the browser users use, but I can send headers to help. What type of headers should I send to tell the browser to cache the image? Quote Link to comment https://forums.phpfreaks.com/topic/111345-will-images-cache-when-called-absolutely/#findComment-571723 Share on other sites More sharing options...
Daniel0 Posted June 22, 2008 Share Posted June 22, 2008 There are a number of different headers you could use. For instance, if you would like it cached for one month then you could do Expires: Tue, 22 Jul 2008 20:42:40 GMT and Cache-Control: max-age=2592000; must-revalidate (one month being 30 days here). Furthermore, keeping Last-Modified accurate and sending an ETag will also help. An ETag is simply, well... a tag. It changes each time the file changes and the client can then check by sending the ETag in a If-None-Match request header. If the ETag matches then the server will send an HTTP 304 Not Modified response header and the browser will then use the cached version instead. If I remember correctly, then ETags where introduced in HTTP 1.1. A combination of the above might be the ideal solution. Quote Link to comment https://forums.phpfreaks.com/topic/111345-will-images-cache-when-called-absolutely/#findComment-571731 Share on other sites More sharing options...
TheFilmGod Posted June 22, 2008 Author Share Posted June 22, 2008 Thanks so much Daniel0! I have a follow up question. What headers are typically sent by the server - by default and without the programmer purposely creating any? Quote Link to comment https://forums.phpfreaks.com/topic/111345-will-images-cache-when-called-absolutely/#findComment-571781 Share on other sites More sharing options...
Daniel0 Posted June 22, 2008 Share Posted June 22, 2008 On a static HTML file on my VPS I received the following response headers: HTTP/1.1 200 OK Date: Sun, 22 Jun 2008 21:53:36 GMT Server: Apache/2.2.3 (Debian) DAV/2 SVN/1.4.2 PHP/5.2.0-8+etch11 mod_ssl/2.2.3 OpenSSL/0.9.8c Last-Modified: Thu, 19 Jun 2008 09:44:58 GMT ETag: "7a8aec-21a-d48c5a80" Accept-Ranges: bytes Content-Length: 538 Content-Type: text/html; charset=UTF-8 Note that the Last-Modified header was set to when I actually last modified it. Apache determines this by the last change time of the file. Quote Link to comment https://forums.phpfreaks.com/topic/111345-will-images-cache-when-called-absolutely/#findComment-571788 Share on other sites More sharing options...
TheFilmGod Posted June 22, 2008 Author Share Posted June 22, 2008 I have one last question - What about dynamically generated files, like php? Do I need to amend the headers sent to ensure that the files aren't cached? Or will apache notice the difference between the static/dynamic files? Quote Link to comment https://forums.phpfreaks.com/topic/111345-will-images-cache-when-called-absolutely/#findComment-571801 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.