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

feat: include only compressible mime types #761

Merged
merged 9 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/content/3.config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,35 @@ If a `public/` directory is detected, it will be added by default, but you can a
If enabled, Nitro will generate a pre-compressed (gzip and/or brotli) version of supported types of public assets and prerendered routes
larger than 1024 bytes into the public directory. The best compression level is used. Using this option you can support zero overhead asset compression without using a CDN.

The compressible MIME types are:

- text/html - `.html`
- text/plain - `.txt`
- text/css - `.css`
- text/xml - `.xml`
- text/x-component - `.htc`
- text/javascript - `.js`
- application/javascript - `.js`
- application/x-javascript - `.js`
- application/json - `.json`
- application/vnd.api+json - `.json`
- application/manifest+json - `.webmanifest`
- application/xml - `.xml`
- application/xhtml+xml - `.xhtml`
- application/rss+xml - `.rss`
- application/atom+xml - `.atom`
- image/svg+xml - `.svg`
- image/x-icon - `.ico`
- image/vnd.microsoft.icon - `.ico`
- font/ttf - `.ttf`
- application/x-font-ttf - `.ttf`
- application/x-font-truetype - `.ttf`
- font/eot - `.eot`
- application/vnd.ms-fontobject - `.eot`
- font/otf - `.otf`
- font/opentype - `.otf`
- application/x-font-opentype - `.otf`

## `serverAssets`

Assets can be accessed in server logic and bundled in production.
Expand Down
4 changes: 3 additions & 1 deletion src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ function isTextMime(mimeType: string) {
return /text|javascript|json|xml/.test(mimeType);
}

danielroe marked this conversation as resolved.
Show resolved Hide resolved
const COMPRESSIBLE_MIMES_RE = /atom|css|eot|htc|html|ico|js|json|mjs|otf|rss|svg|text|ttf|webmanifest|xml/
danielroe marked this conversation as resolved.
Show resolved Hide resolved

function isCompressableMime(mimeType: string) {
return /image|text|font|json|xml|javascript/.test(mimeType);
return COMPRESSIBLE_MIMES_RE.test(mimeType);
}