Ensuring pages are always refresh

Today, I setup a new website, on a Linux hosting account, using cPanel, for a child who’s just learning to code for the web, starting with HTML. An annoying problem, is the caching of pages. Normally, some caching is good, as you don’t want visitors to have to wait when loading resources. When re-loading the same resources (html,js,jpg, etc…) even checking the data on a resource can waste time, so it’s normal that caching will avoid unnecessary hits to the server, if accessing something that was recently loaded. However, when learning HTML, on a small site, it means it’s harder to see the effect of one’s most recent changes. Simply doing a “reload”, “hard reload”, removing cache on browser, and various different settings on the server side, didn’t seem to effectively work. So, ultimately what did work was putting the following in the “.htaccess” code.

# DISABLE CACHING
<IfModule mod_headers.c>
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires 0
</IfModule>

<FilesMatch "\.(css|flv|gif|htm|html|ico|jpe|jpeg|jpg|js|mp3|mp4|png|pdf|swf|txt)$">
    <IfModule mod_expires.c>
        ExpiresActive Off
    </IfModule>
    <IfModule mod_headers.c>
        FileETag None
        Header unset ETag
        Header unset Pragma
        Header unset Cache-Control
        Header unset Last-Modified
        Header set Pragma "no-cache"
        Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
        Header set Expires "Thu, 1 Jan 1970 00:00:00 GMT"
    </IfModule>
</FilesMatch>

While it did work, I wouldn’t recommend it for a typical website, as it would slow down access. But, for my particular purpose, the only thing I cared about, was seeing changes reflected immediately on a reload.