liam icon indicating copy to clipboard operation
liam copied to clipboard

(cache issue) example command "npx http-server dist/" responds with "cache-control: max-age=3600"

Open hoshinotsuyoshi opened this issue 7 months ago • 2 comments

Self Checks

  • [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [x] I have searched for existing issues search for existing issues, including closed ones.

Version Type

CLI Version (npm package)

Version (only for Self Hosted)

0.5.6 latest

Steps to reproduce

When using the following CLI command:

$ npx @liam-hq/cli@latest erd build --input ./frontend/packages/db/schema/schema.sql --format postgres
Need to install the following packages:
@liam-hq/[email protected]
Ok to proceed? (y) y

ERD has been generated successfully in the `dist/` directory.
Note: You cannot open this file directly using `file://`.
Please serve the `dist/` directory with an HTTP server and access it via `http://`.
Example:
    $ npx http-server dist/

And then running the suggested HTTP server command:

$ npx http-server dist/

You can inspect the response headers with:

$ curl -is http://127.0.0.1:8080 | grep cache-control
cache-control: max-age=3600

Problem: The server responds with a cache-control: max-age=3600 header, which causes the client to cache the content for an hour. This behavior is problematic because the tool is primarily intended for development use. In such scenarios, it is preferable to add no-store or no-cache to the response headers to ensure that any changes in the dist/ directory are immediately reflected in the browser.

Suggestion:

  • Adding the -c-1 option to the command example seems like a good approach to disable caching.
  • Alternatively, using a different npm package like serve might be a viable option. As far as I’ve tested, it doesn’t add a cache-control header by default. While that leaves caching behavior up to the browser, it’s still likely to be an improvement over http-server in this context—though the actual effect may vary.

Note: This idea was inspired by a public blog post: https://tech.gree-x.com/automated-er-diagram-generation/index.html

Expected Behavior

e.g. cache-control: no-cache

Actual Behavior

e.g. cache-control: max-age=3600

Additional Context

No response

hoshinotsuyoshi avatar May 27 '25 07:05 hoshinotsuyoshi

@hoshinotsuyoshi Thank you very much, that's nice!

My stance is to replace all documentation with serve. "Why should I set this option with http-server?" It is not intuitive for the user to have to think about.

MH4GF avatar May 27 '25 08:05 MH4GF

@MH4GF

My stance is to replace all documentation with serve. Asking users to think about “Why do I need to set this specific option with http-server?” isn't intuitive.

Sounds good — let’s go with that. I originally chose http-server for its longer history and slightly more established reputation. But both http-server and serve are widely-used and reliable libraries, and either would have been a reasonable default.

This time, we’ll switch to serve, as its default behavior around caching is a bit simpler.


serve doesn’t add a Cache-Control header by default. While that leaves caching behavior up to the browser, it’s still likely to behave better than http-server in this context — though the actual effect may vary.

If we go with serve, it seems best to include a serve.json file in the appropriate location — in our case, probably directly under dist. The following resources provide helpful guidance:

  1. https://github.com/vercel/serve#configuration
  2. https://github.com/vercel/serve-handler#options

hoshinotsuyoshi avatar May 27 '25 08:05 hoshinotsuyoshi