hexojs / hexo-server

Server module for Hexo.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disable browser catching thorugh headers

jakubgs opened this issue · comments

commented

The hexo server should have an ability to disable browser caching by adding headers like:

Cache-Control: no-cache, must-revalidate
Expires: Sat, 26 Jul 1997 05:00:00 GMT

Or something to that effect. Doesn't have to be so by default, it could be a config option.

This would avoid mistaking lack of some changes appearing after refresh as a problem with the generation phase.

hexo-server is only used for debug purpose, it doesn't provide full functions as a server. I recommend to use nginx as static content server, which is also easy to setup and expand.

commented

Yeah, and that's precisely the point. You run it while you develop/debug stuff. In those kind of situations it would be better to not have the result of generation be affected by browser caching.

We tried to keep the function as simple as possible, just provide the ability to preview the Hexo generated files. For caching, header meta, those more advanced settings could be debugged in more advanced tools.

commented

I think you are mistaking my purpose here.

I don't want hexo-server to support complex headers that I could configure myself. I want hexo-server to send these headers by default because caching in browsers can sometimes cause a lot of confusions, especially for new users.

I'm talking here about caching built into browsers, see this as an example.

A bare minimum would be to include at least Cache-Control: no-cache.

Understood. I thought it in the opposite way. It could be an enhancement.

I was just experiencing an issue where a browser was too dumb to "hard refresh" and it kept caching everything. The feature to not cache is built-in to this module:

# hexo-server plugin
server:
  port: 4000
  log: false
  ip: 127.0.0.1
  serveStatic:
    cacheControl: false
    etag: false
    maxAge: -1

https://github.com/hexojs/hexo-server#options

commented

If that is a "built-in" feature of the module then why can't I see any mention of cacheControl in the README file? Shouldn't that be fixed?
Also, why is this not enabled by default? If someone is in development mode one would expect no caching to occur, since we are constantly changing the page.

@PonderingGrower good questions. I'm not sure why caching is not disabled by default. 🤷‍♂️ I always have that problem with node modules for static files.

Like many hexo modules they implement some other module for hexo and we don't repeat their documentation. We link to it down there at the bottom. Not trying to confuse anyone. https://github.com/hexojs/hexo-server#options

I would be open to having it disable caching by default. I wonder if it would cause problems for anyone. Does anyone know? 🤔

We can re-open if there is interest.