1

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

Manu Chadha
  • 11,886
  • 11
  • 51
  • 115
  • Are you certain its not the browser caching local resources? http://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development – tgk Mar 20 '17 at 19:52

1 Answers1

2

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.

Community
  • 1
  • 1
Andriy Kuba
  • 7,595
  • 2
  • 22
  • 42
  • Thanks. I am on Play 2.2.6, sbt 0.13.0. Earlier I was using ``. I changed it to ``. made the change in build.sbt and plugins.sbt as well. But my Javascript didnt load. I think `pipelineStages` isn't defined for the version of play I am using. – Manu Chadha Mar 21 '17 at 08:12
  • You was correct - my post was not enough clear, so return back your changes. I still think your versioned pipeline does not work correctly. – Andriy Kuba Mar 21 '17 at 09:04