Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't cache localhost imports (or give an option to turn it off) #15509

Closed
mimbrown opened this issue Aug 20, 2022 · 6 comments
Closed

Don't cache localhost imports (or give an option to turn it off) #15509

mimbrown opened this issue Aug 20, 2022 · 6 comments
Labels

Comments

@mimbrown
Copy link

The reason Deno caches remote imports, in my understanding, is (a) so that subsequent runs will be faster, and (b) so that previously imported modules can be imported even offline. Caching can be done without causing problems because we assume the content delivered by the server is (mostly) not going to keep changing on us.

None of this is true when the "remote" is localhost. The content isn't actually remote, so the speedup is probably negligible. Localhost works fine offline. And, most importantly, the assumption that the content being served is not changing is often wrong (i.e. in an active development context, which is what localhost is normally used for).

There's plenty of precedent for treating localhost differently, for example, Chromium treats localhost as a secure context even over http.

I propose that the default behavior be for Deno to not cache imports from localhost. Possibly it would be worth adding a flag to force even localhost files to be cached as well, though I'm stumped to come up with a legitimate use case for that.

@bartlomieju
Copy link
Member

You can achieve that by specifying --reload=http://localhost

@mimbrown
Copy link
Author

You can achieve that by specifying --reload=http://localhost

Yes that fixes some problems, but not all. First, that doesn't prevent Deno from caching, just forces it to ignore the cache. I don't actually want the increased cache size that comes from caching all imports that come through localhost. With that, if I'm developing a site with 500 modules, I don't want to see 500 Download http://localhost:8080/whatever messages on my console every time I refresh.

But on principle, I would argue I shouldn't have to pass a flag to get behavior that should be the default. It doesn't make any sense, IMO, for localhost imports to be cached. What happens if I forget the flag? Suddenly the file I'm importing could actually be serving up a pre-cached file from a separate project on the same machine that happens to have the same name and was imported earlier using the same localhost port. That could lead to some hair pulling bug hunts.

@stale
Copy link

stale bot commented Oct 21, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@swwind
Copy link

swwind commented Oct 3, 2023

Adding a reload option does not prevent deno from panicking when localhost import updates and failed to match lock file.

image

@asyncanup
Copy link

How can we un-stale this issue?

@bartlomieju
Copy link
Member

How can we un-stale this issue?

I suggest to open a new issue with description of your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants