Question
· Feb 10, 2017

How do I disable cache for static files in web application

I have a web application with html, css, js files (no ZEN/CSP).

Problem: after I update them on a server, Caché still servers old and cached version (browser Cache is disabled).

There is a manual cache purge in Gateway Settings, of course, but is there an automatic solution?

I'll be okay with disabling cache server-wide, but an application-wide solution would be better.

I don't want to host web app on a separate web server.

Here's my web app config:

Discussion (5)0
Log in or sign up to continue

I had assumed that if the "Serve Files" setting isn't "Always and cached" then the Gateway wouldn't cache them.

Doc at http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=... seems to imply this.

That doc also states that the "Serve Files Timeout" is to do with caching by the browser.

Anyway, it'll be interesting to hear what your tests show.

Correct, the gateway will not cached files that are not served from 'always and cached'. Of course if you served a static file when this was set and then unset this then the gateway will still have it in its cache. Also the timeout value applies both to the browser timeout period and the CSP gateway timeout period.

You can also remove items from the gateway cache using code (which we do automatically when you edit a static file in Studio):

Set registry = $System.CSP.GetGatewayRegistry()

Set sc=registry.RemoveFilesFromCaches(remove)

See the class %CSP.Mgr.GatewayRegistry for more details of this method.

I change the names of the files in order to do that, like this:

csp file:

<!DOCTYPE html>
<html>
<head>
<csp:include page="includes/libraries.csp"/>
<title></title>
</head>

inside the includes/libraries.csp file, rename the file as "jquery-1.11.3.min.js" instead of just use the file as "jquery.min.js" :

 <script src="jquery/jquery-1.11.3.min.js"></script> 

this in order to avoid the server to load the old file