chore: minor reduction to inline svg/js code#11317
Merged
slorber merged 2 commits intofacebook:mainfrom Jul 15, 2025
Merged
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
slorber
requested changes
Jul 11, 2025
Collaborator
slorber
left a comment
There was a problem hiding this comment.
Thanks
I think we can consider it's not a breaking change
Comment on lines
+7
to
+10
| } | ||
|
|
||
|
|
||
| function getQueryStringTheme() { |
Collaborator
There was a problem hiding this comment.
Can we reduce line breaks and useless indentation?
This doesn't matter much (if minimization is enabled), but it looks a bit messy
Contributor
Author
There was a problem hiding this comment.
Done! Let me know if you're fine with that!
I did it this way before as my aim was to keep the source clean rather than the output. Now that we've prioritized a clean output, I feel the source looks a bit messy now, though.
I'm starting to see the appeal to tc39/proposal-string-dedent.
30de303 to
362c71a
Compare
Collaborator
|
Thanks 👍 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pre-flight checklist
Motivation
I've been looking at the output of SVGO.dev and just trying to see where we could reduce the bundles further. (Switching to Preact, writing PostCSS plugins, hand-editing our SVGs, etc.)
These are two things I noticed during my review that were upstream. The changes are petty at best, but do reduce the inlined SVG/JS code by 0.25 KB and reduce the amount of JavaScript that is executed on the client. It's not much, but at least it's a quick win. ^-^'
Redundant XMLNS in SVG
Removes
xmlnsfrom the inlined sprite sheet icon.There's no need to specify the XMLNS when inlining an SVG into an HTML document. HTML rules apply rather than XML rules! I believe this is a safe change, inline SVGs have worked without
xmlnsall the way back with IE 9! The SVGs in this screenshot don't havexmlns.Before vs. After in the Build Output (⬇️ 0.035 KB)
As an aside, these are the same sources you can reference for the rationale behind enabling
removeXMLNSby default in the issue for better SVGO defaults.Reduce Theming JavaScript
This makes two changes:
disableSwitchis enabled, there's no need to even inline the functions to read the theme setting from the URL or localStorage. The option to set it shouldn't be there anyway!disableSwitchwas enabled, it was still possible to force light mode through?docusaurus-theme=light. ThedisableSwitchoption would now disable both the button and the query parameter.Before vs. After in the Build Output (⬇️ 0.206~ KB)
This may require consideration as it could be a breaking change. Depends on if the following is a supported scenario. A user sets
disableSwitchtotrue, because they want to implement their own switch without swizzling, but they still wants Docusaurus to be responsible for thedata-themeattribute. 🤔Test Plan
Test links
Deploy preview: https://deploy-preview-11317--docusaurus-2.netlify.app/