-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
perf: phase 1 - compression & image optimization (@abdo-spices) #7014
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please delete the replaced
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to keep the original images
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? Image optimization will pick them up and they are not used.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I can delete them, but it's better to keep them we might switch the image optimizer or convert them to other formats later if needed.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think ideally we would keep the originals, but also dont commit the compressed files, only output them to the dist directory when deploying. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ import DEV_CONFIG from "./vite.config.dev"; | |
| import MagicString from "magic-string"; | ||
| import { Fonts } from "./src/ts/constants/fonts"; | ||
|
|
||
| global.navigator = undefined; // sass compatibly & imagemin bug https://github.com/vitejs/vite/issues/5815#issuecomment-984041683 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Youre linking a closed issues from 4 years ago, are you sure this is needed? |
||
|
|
||
| /** @type {import("vite").UserConfig} */ | ||
| const BASE_CONFIG = { | ||
| plugins: [ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ import { readdirSync, readFileSync, statSync } from "node:fs"; | |
| import { ViteMinifyPlugin } from "vite-plugin-minify"; | ||
| import { sentryVitePlugin } from "@sentry/vite-plugin"; | ||
| import { getFontsConig } from "./vite.config"; | ||
| import { compression, defineAlgorithm } from "vite-plugin-compression2"; | ||
| import { ViteImageOptimizer } from "vite-plugin-image-optimizer"; | ||
|
|
||
| function pad(numbers, maxLength, fillString) { | ||
| return numbers.map((number) => | ||
|
|
@@ -252,6 +254,10 @@ export default { | |
| ); | ||
| }, | ||
| }, | ||
| ViteImageOptimizer(), | ||
| compression({ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Takes about 26s on my machine, and yeah, the Spanish list file (~1MB) is the main bottleneck at ~80% of compression time. I think pre-compression is worth it though server load (if it's not the CDN): If the server is handling compression instead of the CDN, that's CPU being used on every request. Pre-compression moves that work to build time, which happens way less frequently.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
any source on that? I'd hope firebase would cache the compressed file and not compress it each time it is requested. Besided, how is it working? The plugin generates an additional
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
All files can be compressed not just JS or CSS, but also images and JSON. When the browser detects a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Firebase is already compressing files on upload. When i check a url that bypasses cloudflare everything is already compressed. So im not sure this is needed. |
||
| algorithms: [defineAlgorithm("brotliCompress", { level: 9 })], | ||
| }), | ||
| ], | ||
| build: { | ||
| sourcemap: process.env.SENTRY, | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason for this two year old version of sharp? the current version is
0.34.4There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is bug in modern sharp binary that specific version do not have it so we need 0.32.6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which bug, please link the source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the bug is mainly with build script in sharp i can fix it in my device but well break on other people machines
lovell/sharp#1783
lovell/sharp#400
lovell/sharp#1627 (comment)
there is more cases
it also happen on windows, the it's also known bug in astro since a lot of astro projects uses image component that's powered by sharp
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Youre linking very old issues here. Are you sure this is a problem?