Skip to content

Add more granular control for source-code browser caching #7888

@dorshinar

Description

@dorshinar

Clear and concise description of the problem

I would like to have the option to control cache headers for source code that doesn't change often, so I can more aggressively cache chunks of my application while developing, without using Cache-Control: max-age=31536000,immutable.

Suggested solution

Today, Vite divides code into 2 categories - dependencies, which are pre-bundled and strongly cached, and source code which is never cached.
I'd like to propose a solution - allow users to set stale-while-revalidate cache headers for files that are known to change seldom.
This way we rip the benefits of all sides. With a small enough max-age we can ensure the browser almost always requests fresh content in the background, but the initial load is still super fast thanks to using the now-stale files.

Alternative

An alternative solution would be to use the optimizeDeps.include option in Vite's config, but I believe it some-what defeats the purpose.

Additional context

Large applications can contain thousands of modules, not all of which update frequently.
This causes initial (and sometimes subsequent) refreshes to be rather slow, taking sometimes as much as 30 seconds before the page is fully loaded.

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance related enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions