@Jim Using one method is enough, htaccess, PHP or HTML.
When you use more methods (at a time), they are processed/overruled in that order.
By using the HTML method, you have to add it to every single HTML file (can be a lot of work). Using htaccess, you can configure it for the whole site (or directory) with just one htaccess file.
DO I NEED IT ?
I would like to mention that “disabling caching” looks very attractive and a perfect solution, but it’s not always a good idea, I would only use it when there is a very good reason!
Because when disabled it means more (maybe unnecessary) requests, data traffic and load to the server. On a slow/crowded or very high traffic server, it’s not always desirable.
And with a slower (mobile) connection, it takes longer to constantly load everything again from the server, which is not good for a positive user experience. And for connections with a dataplan (mobile), it cost more data for the user(s) from their dataplan.
MAX-AGE and FILESMATCH
When your pages/content is not constantly changing. It’s not really necessary to disable caching. Better leave it as it is, or maybe use and configure a “Max-Age” or a “Expiration” value. For lets say: 15 min, 1 hour, 1 day or a week.
And with htaccess and “FilesMatch” you can control it easily by filetype, and use different control settings.
htaccess file (example)
<IfModule mod_headers.c>
# no caching
<FilesMatch "\.(html|htm|php)$">
Header set Cache-Control "no-cache, no-store, must-revalidate, private"
Header set Pragma "no-cache"
Header set Expires 0
</filesMatch>
# 1 day - max-age
<FilesMatch "\.(txt|xml|js|css)$">
Header set Cache-Control "max-age=86100, public"
</FilesMatch>
# 1 week - max-age
<FilesMatch "\.(jpg|jpeg|png|gif)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
</IfModule>
-
max-age : Values are set in seconds.
-
public : Indicates that the response may be cached by any cache.
-
private : Indicates that the response is intended for a single user and must not be stored by a shared cache. A private cache may store the response.
DEVELOPMENT STAGE
While you are still in developing stage, and constantly making changes. Caching can be very annoying!
You can decide to temporarily disable it (with htaccess) during the development process.
When the site/project is done and ready to publish, you can easily remove the caching limitations for the production server (remove/change that htaccess file).