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

Apply a custom cache configuration for static assets #32

Open
bpetetot opened this issue Jul 24, 2024 · 5 comments
Open

Apply a custom cache configuration for static assets #32

bpetetot opened this issue Jul 24, 2024 · 5 comments

Comments

@bpetetot
Copy link

bpetetot commented Jul 24, 2024

I wanted to be more aggressive on my font cache by explicitly adding this configuration:

createExpressApp({
  configure: (app) => {
    // ...
    // Cache assets
    app.use('/fonts', express.static('build/client/fonts', { immutable: true, maxAge: '1y' }));
  }
})

But the server's default configuration for static files (for build/client) is made with a maxAge: '1h'.

app.use(
express.static(isProductionMode ? `${buildDirectory}/client` : 'public', {
maxAge: '1h',
}),
)

So we can't replace cache-control for specific static files (like fonts) with a custom configuration.

Could we have the default configuration for static files after the custom configuration is applied? (I can do the PR if needed)

Thank you for this awesome project 🔥

@kiliman
Copy link
Owner

kiliman commented Jul 24, 2024

Sure, I should probably allow you to provide defaults.

@kiliman
Copy link
Owner

kiliman commented Jul 24, 2024

If you have time to provide a PR, that would be great; otherwise, I probably won't get to it until this weekend. You can always use patch-package if it's a blocker for you.

@bpetetot
Copy link
Author

Thanks kiliman, it can be done later, it's not a blocker for me.

@kiliman
Copy link
Owner

kiliman commented Jul 26, 2024

Although not exactly the cache setting we discussed, v0.4.5, which was just released, should fix this. Your configure function will be called before I set the static paths, so your specific /fonts entry will be handled before the default.

@bpetetot
Copy link
Author

Great! Thanks 👍

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

No branches or pull requests

2 participants