typelevel / Laika

Site and E-book Generator and Customizable Text Markup Transformer for sbt, Scala and Scala.js
https://typelevel.org/Laika/
Apache License 2.0
406 stars 44 forks source link

Laika Preview: No cache headers #579

Closed davesmith00000 closed 5 months ago

davesmith00000 commented 5 months ago

Hi,

I was wondering if it is possible to tell Laika's preview to use no caching so that the browser always fetches your changes.

The issue is that if the browser's cache your site during development, and you forget to clear you browser's cache, then you won't see your changes you have made reflected in the page, and you might mistake that for something you did incorrectly, when actually it's just the browser cache.

I use http-server for similar but unrelated purposes, and what I'm looking for is something like it's http-server -c-1 behaviour:

Set cache time (in seconds) for cache-control max-age header, e.g. -c10 for 10 seconds. To disable caching, use -c-1.

jenshalm commented 5 months ago

The preview server actually does add those headers here: https://github.com/typelevel/Laika/blob/main/preview/src/main/scala/laika/preview/internal/RouteBuilder.scala#L64 and when I run the server myself and check the headers of the response, they are present. Can you double-check in the browser that the headers are indeed missing for you?

davesmith00000 commented 5 months ago

Hi @jenshalm,

Ah. I confess I did not investigate further it before writing up the issue, apologies. What happened was that I got two different pages (static asset differences, I think) in two different browsers, one I'd been working in (chrome) and the other a fresh session (firefox), and I jumped to the conclusion that it was the headers.

Looking at the code, I can see you've gone with the no-store header, which according to this MDN page, suggests that it should do the trick (there is literally an example of this):

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#use_cases

...so I don't know what happened. I'll close the issue, and re-open if it occurs again, but will include steps to re-produce.

Thanks for you time!