Reputation: 16735
Whenever I make changes to my CSS file, Play framework does not pick the latest file. It seems it has cached an old version and keeps using it. How could I enforce that the file should be picked from server, not from browser cache (or wherever it is picking the css, javascript files from)?
I am running the server on local machine and use localhost:9000 to access the server
Upvotes: 1
Views: 554
Reputation: 8263
You need to use versioned assets. Make sure that you use controllers.Assets.versioned
in routes
:
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
In HTML template:
<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>
And do not forget to configure versioning in the build.sbt
// Production.
pipelineStages := Seq(digest)
// Development.
pipelineStages in Assets := Seq(digest)
You need to have digist
plugin enabled in project\plugins.sbt
as well
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.1")
Resulting HTML:
<script src="/assets/javascripts/a7c0637aa0972b62ef0c436a66be57b1-hello.js" type="text/javascript"></script>
So it will not have the cache problem because file name will be new after every update of the file.
Upvotes: 2