Website with optimal cache management

My goal
I would like browsers to cache my entire site, but only load static content when I modify one or more files.

My situation
After some research, I found a way to do this. That is, to add the Far Future Expires Header file to my htaccess and add files to them using the filemtime() function.

Problem
When I click on the address bar and type in the address of my site in firefox, then Firebug displays
38.3 KB (36.4 KB from cache)

When I press F5 in firefox, Firebug shows:
241.1 KB (10.9 KB from cache)

Now I tried to do the same with Google, and they send the HTTP 304 header back. I read a lot about ETag and the Last Modified header, but I heard a lot of people saying that they are not very reliable.

My question
What would be a better solution if I wanted to send the HTTP 304 header back with static content if the user clicks on F5, like Google?

I ask this question because I often visit the site and use F5 to find out if there is any new information. Do not reload images, etc.



Refresh
It seems that Firefox controls the way the cache is used, and I would like to use the cache when the user presses F5.

+6
php caching header .htaccess
source share
3 answers

The very purpose of reloading is to reload the page. There is no server-side header magic if the browser was skipped to ignore caches when the user specifically requests it.

The solution for Google is that you check if the crawler sent the If-Modified-Since header with:

 if ($_SERVER["HTTP_IF_MODIFIED_SINCE"]) { header("HTTP/1.0 304 Not Modified"); exit(); } 

This trick may work for browsers, but not in forced reboot modes such as Firefox SHIFT + RELOAD.

+2
source share

You can also use the new application caching.
I don’t know what your target browser is, but most browsers have supported it for quite a few versions so far ..
That way, you can determine that your statics load only once.

For very good information on this topic, you can take a look at this page:
http://diveintohtml5.ep.io/offline.html

+1
source share

I'm not sure I understand the meaning of your question, but you can specify the response code in php with a header function, regardless of whether your user clicks a button.

http://php.net/manual/en/function.header.php

0
source share

All Articles