Prevent browser from creating a cache of page

I was wondering if there is a feature or setting that will prevent the browser from saving a cache of a webpage so that it is required to load from the server each time it is opened?

@Russ, What is your reason for it?..

Welcome @Russ, there are server configurations to do that, Sparkle doesn’t have it built-in yet because the different web servers aren’t all configured in the same way.

If your web host uses an Apache web server, one of the most popular, the configuration is straightforward.

What you do is use the file manager of your web host to create a file in the top level of the website, named .htaccess, and add this content:

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json application/x-font-ttf
</IfModule>

Options -Indexes

<ifModule mod_headers.c>
<ifModule mod_expires.c>
  # expire html immediately
  ExpiresActive On
  ExpiresByType text/html "access plus 0 seconds"
  # images, css and js for 365 days
  <filesMatch "\.(jpeg|jpg|png|gif|webp|pdf|ico|css|js|eot|ttf|ttc|otf|woff|woff2|svg)$">
    ExpiresDefault "access plus 365 days"
    Header set Cache-Control "public, max-age=31536000"
  </filesMatch>
</ifModule>
</ifModule>

This is a boilerplate of a couple different things, including configuring transfer compression, it essentially makes html files expire immediately, so the visitor will always reload html, but it makes all other files types expire after one year. This works well specifically with how Sparkle produces files, always regenerating the css when publishing.

2 Likes

Great thanks Duncan. I will try this.