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

Allow user decide which npm deps should be cached by browser #370

Open
4 tasks done
windsonR opened this issue Mar 16, 2024 · 3 comments
Open
4 tasks done

Allow user decide which npm deps should be cached by browser #370

windsonR opened this issue Mar 16, 2024 · 3 comments

Comments

@windsonR
Copy link

Description

The feature allow browser to cache npm deps deps is very useful, but it has a problem like this repo

reproduction steps:

  1. Download repo and pnpm install
  2. Start vite dev-server
  3. In browser, access http://localhost:5173/
  4. wait for page loaded
  5. make sure devtools=>Network=> disable cache not checked!
  6. restart vite dev-ser
  7. wait for browser load page

Browser page will display errors.

Suggested solution

When send cached request, allow user define a callback or RegExp to disable some npm deps' cache

A possibly implementation:

defineConfig({
server:{
npmCacheStrategy(url){
return url.indexOf('?')<0
}
}
})

Alternative

No response

Additional context

No response

Validations

@sapphi-red sapphi-red transferred this issue from vitejs/vite Mar 16, 2024
@sapphi-red
Copy link
Member

sapphi-red commented Mar 16, 2024

Since demo is a dependency, demo.vue gets cached and it doesn't hit the server. But plugin-vue expects demo.vue to be processed before demo.vue?vue&type=script and it skips the transform.


Specifically, this condition is false.

@windsonR
Copy link
Author

Both @vitejs/plugin-vue and @vitejs/plugin-vue2 plugins have this issue.
If it fix in the plugins, you may need to add a fallback when loading the script(demo.vue?vue&type=script) to check if the corresponding Vue file(demo.vue) has already been loaded?
In my opinion, controlling Cache Control on certain files may be simpler and more adaptable to different situations?

@windsonR
Copy link
Author

At present, I can only temporarily solve this problem by disabling the browser cache

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

No branches or pull requests

3 participants