How To Update Javascript Cache

17 views
Skip to first unread message

Nick Mudge

unread,
Feb 6, 2019, 3:32:17 PM2/6/19
to Luminus
When I deploy my Luminus application to production my users do not get the newest javascript "/js/app.js" file that is generated from clojurescript/reframe.  This file is cached in my users browsers.

What is the best way to fix this problem?

Thanks
Nick Mudge

Dmitri

unread,
Feb 6, 2019, 7:52:18 PM2/6/19
to Luminus
Hi,

The most common way to address this is to add a timestamp to the Js file. If you're using Selmer for HTML templating, then you'd want to add something like the following:

<script src="{{servlet-context}}/js/app.js?{{timestamp}}" type="text/javascript"></script>

Then in the layout namespace you'd create a timestamp generated when the app compiles:

(def timestamp (.getTime (java.util.Date.)))

and pass it to the template in the render function as :timestamp

Here's an example in project for reference:

https://github.com/yogthos/memory-hole/blob/a78659415488be57e60975d9f2bcfa4a610c7cde/resources/templates/home.html#L32
https://github.com/yogthos/memory-hole/blob/a78659415488be57e60975d9f2bcfa4a610c7cde/src/clj/memory_hole/layout.clj#L15

Nick Mudge

unread,
Feb 7, 2019, 4:51:44 PM2/7/19
to Luminus
Yes, this is very helpful. Thanks Dmitri.

Nick
Reply all
Reply to author
Forward
0 new messages