-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Improve Lighthouse Scrore #6296
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
Open
FarhanAliRaza
wants to merge
18
commits into
reflex-dev:main
Choose a base branch
from
FarhanAliRaza:lighthouse-improve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2ec0b7a
lighthouse test
FarhanAliRaza 8ca31a5
Improve Lighthouse scores and add landing page benchmark
FarhanAliRaza cb3e850
Add gzip pre-compression plugin and optimize Vite chunk splitting
FarhanAliRaza 40d5aa7
warmup request
FarhanAliRaza 3f6f2a0
Add configurable pre-compression formats and serve precompressed stat…
FarhanAliRaza cacc11b
feat: add image optimization, CSS purging, and shared Vite plugin uti…
FarhanAliRaza 11aae47
Merge remote-tracking branch 'upstream/main' into lighthouse-improve
FarhanAliRaza 10d0893
feat: add post-build static compression and use JSON5 for socket parsing
FarhanAliRaza a633787
removed purge css because purgre css does not really work withh radix…
FarhanAliRaza 56fe0f2
feat: serve precompressed static assets in frontend mount
FarhanAliRaza 195986b
feat: use static imports for window libraries and simplify layout setup
FarhanAliRaza 522bcc0
Merge remote-tracking branch 'upstream/main' into lighthouse-improve
FarhanAliRaza 6f9543f
test: add missing prepend_frontend_path param
FarhanAliRaza dd6803e
feat: make node version configurable and improve timeout error messages
FarhanAliRaza fa39149
perf: tree-shake radix themes and window.__reflex imports
FarhanAliRaza 31820ec
fix: expose dynamic component tags on window.__reflex
FarhanAliRaza d8c9bea
Update packages/reflex-base/src/reflex_base/plugins/shared_tailwind.py
FarhanAliRaza cd16bf4
fix: greptile code fix
FarhanAliRaza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/reflex-base/src/reflex_base/.templates/web/compress-static.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { compressDirectory } from "./vite-plugin-compress.js"; | ||
|
|
||
| const [directory, formatsArg = "[]"] = process.argv.slice(2); | ||
|
|
||
| if (!directory) { | ||
| throw new Error("Missing static output directory for compression."); | ||
| } | ||
|
|
||
| await compressDirectory(directory, JSON.parse(formatsArg)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
packages/reflex-base/src/reflex_base/.templates/web/vite-plugin-compress.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| /* vite-plugin-compress.js | ||
| * | ||
| * Generate pre-compressed build assets so they can be served directly by | ||
| * production static file servers and reverse proxies without on-the-fly | ||
| * compression. The default format is gzip, with optional brotli and zstd. | ||
| */ | ||
|
|
||
| import * as zlib from "node:zlib"; | ||
| import { dirname } from "node:path"; | ||
| import { access, readFile, writeFile } from "node:fs/promises"; | ||
| import { promisify } from "node:util"; | ||
| import { | ||
| validateFormats, | ||
| outputDirectoryExists, | ||
| walkFiles, | ||
| } from "./vite-plugin-utils.js"; | ||
|
|
||
| const gzipAsync = promisify(zlib.gzip); | ||
| const brotliAsync = | ||
| typeof zlib.brotliCompress === "function" | ||
| ? promisify(zlib.brotliCompress) | ||
| : null; | ||
| const zstdAsync = | ||
| typeof zlib.zstdCompress === "function" ? promisify(zlib.zstdCompress) : null; | ||
|
|
||
| const COMPRESSIBLE_EXTENSIONS = /\.(js|css|html|json|svg|xml|txt|map|mjs)$/; | ||
|
|
||
| // Only compress files above this size (bytes). Tiny assets rarely benefit, | ||
| // but HTML entrypoints are always compressed so their negotiated sidecars exist. | ||
| const MIN_SIZE = 256; | ||
|
|
||
| const COMPRESSORS = { | ||
| gzip: { | ||
| extension: ".gz", | ||
| compress: (raw) => gzipAsync(raw, { level: 9 }), | ||
| }, | ||
| brotli: brotliAsync && { | ||
| extension: ".br", | ||
| compress: (raw) => | ||
| brotliAsync(raw, { | ||
| params: { | ||
| [zlib.constants.BROTLI_PARAM_QUALITY]: | ||
| zlib.constants.BROTLI_MAX_QUALITY ?? 11, | ||
| }, | ||
| }), | ||
| }, | ||
| zstd: zstdAsync && { | ||
| extension: ".zst", | ||
| compress: (raw) => zstdAsync(raw), | ||
| }, | ||
| }; | ||
|
|
||
| // Concurrency limit for parallel file compression. | ||
| const CONCURRENCY = 16; | ||
|
|
||
| function ensureFormatsSupported(formats) { | ||
| const unavailableFormats = formats.filter( | ||
| (format) => !COMPRESSORS[format]?.compress, | ||
| ); | ||
| if (unavailableFormats.length > 0) { | ||
| throw new Error( | ||
| `The configured frontend compression formats are not supported by this Node.js runtime: ${unavailableFormats.join(", ")}`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| async function compressFile(filePath, formats) { | ||
| const pendingFormats = []; | ||
| for (const format of formats) { | ||
| const compressor = COMPRESSORS[format]; | ||
| try { | ||
| await access(filePath + compressor.extension); | ||
| } catch { | ||
| pendingFormats.push([format, compressor]); | ||
| } | ||
| } | ||
|
|
||
| if (pendingFormats.length === 0) return; | ||
|
|
||
| const raw = await readFile(filePath); | ||
| if (raw.length < MIN_SIZE && !filePath.endsWith(".html")) return; | ||
|
|
||
| await Promise.all( | ||
| pendingFormats.map(([_format, compressor]) => { | ||
| return compressor | ||
| .compress(raw) | ||
| .then((compressed) => | ||
| writeFile(filePath + compressor.extension, compressed), | ||
| ); | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| export async function compressDirectory(directory, formats = ["gzip"]) { | ||
| validateFormats(formats, COMPRESSORS, "frontend compression format"); | ||
| ensureFormatsSupported(formats); | ||
|
|
||
| if (!(await outputDirectoryExists(directory))) { | ||
| return; | ||
| } | ||
|
|
||
| const pending = []; | ||
| for await (const filePath of walkFiles(directory)) { | ||
| if (!COMPRESSIBLE_EXTENSIONS.test(filePath)) continue; | ||
| pending.push(filePath); | ||
| } | ||
|
|
||
| for (let i = 0; i < pending.length; i += CONCURRENCY) { | ||
| await Promise.all( | ||
| pending | ||
| .slice(i, i + CONCURRENCY) | ||
| .map((file) => compressFile(file, formats)), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Vite plugin that generates pre-compressed files for eligible build assets. | ||
| * @param {{ formats?: string[] }} [options] | ||
| * @returns {import('vite').Plugin} | ||
| */ | ||
| export default function compressPlugin(options = {}) { | ||
| const formats = options.formats ?? ["gzip"]; | ||
| validateFormats(formats, COMPRESSORS, "frontend compression format"); | ||
|
|
||
| return { | ||
| name: "vite-plugin-compress", | ||
| apply: "build", | ||
| enforce: "post", | ||
|
|
||
| async writeBundle(outputOptions) { | ||
| const outputDir = | ||
| outputOptions.dir ?? | ||
| (outputOptions.file ? dirname(outputOptions.file) : null); | ||
| if (!outputDir) return; | ||
| await compressDirectory(outputDir, formats); | ||
| }, | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
lighthousejob falls back tonpx --yes lighthouse@13.1.0(viaget_lighthouse_command()) when nolighthousebinary is found, relying on whatever Node.js version is pre-installed onubuntu-22.04. The exact Node.js version shipped with GitHub's runner images can change without notice and is not formally guaranteed.Adding an explicit
actions/setup-nodestep would make the workflow reproducible across runner image updates: