Skip to content

StaticFileMiddleware serve pre-compressed file when found by file provider #38295

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

Closed
msschl opened this issue Nov 11, 2021 · 2 comments
Closed
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares feature-static-files

Comments

@msschl
Copy link
Contributor

msschl commented Nov 11, 2021

Is your feature request related to a problem? Please describe.

Today, most sites have a build system in place to build, uglify, compress, remove unused code from static web assets such as css, js, or other assets. One such a build system could be webpack as an example. Furthermore, some sites might use such build systems to pre-compress some static assets to reduce the runtime load. The StaticFileMiddleware added by UseStaticFiles has currently no ability to serve a pre-compressed file if present or fallback to the uncompressed file.

Describe the solution you'd like

It would be nice to add an opt-in option to the StaticFileOptions to enable serving pre-compressed files if present or otherwise falling back to the original uncompressed file.

The implementation would be straight forward I think. In the StaticFileContext.cs#L115 the file provider could be additionally queried for a compressed version of the requested file according to the accept-encoding request header. If a version of a pre-compressed file exists the StaticFileContext would serve the pre-compressed file and the content-encoding would be set accordingly. The content-type would be unaffected as it is retrieved by IContentTypeProvider from the originally requested path.
If there is no pre-compressed file available (i.e. the IFileInfo.Exists property returned by the file provider is false), the StaticFileContext would fallback and serve the normal uncompressed file.

@davidfowl
Copy link
Member

cc @DamianEdwards @javiercn

@Tratcher
Copy link
Member

Duplicate of #2458

@Tratcher Tratcher marked this as a duplicate of #2458 Nov 11, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2021
@amcasey amcasey added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares and removed area-runtime labels Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares feature-static-files
Projects
None yet
Development

No branches or pull requests

5 participants