perf: optmize page load time #726
Open
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.
Type of change
Checklist
Related Issue
Fix: #637 (comment)
Changes
PhotoSwipeonly when images are present on the pagerequestAnimationFrameand cached calculationsToo long
src/utils/preload-icons.ts:src/components/misc/BrandIcon.svelte:scripts/get-icon-data.js — Dev helper to fetch official icon data from Iconify API for adding new icons to preload-icons.ts
astro.config.mjs:
targettoesnextfor aggressive tree-shaking (Aggressive improvement for mobile users)@iconify-jsonpackages from Vite dep optimizationinlineStylesheets: 'auto'for critical CSS inlining (slightly decrease mobile page load time)src/layouts/Layout.astro:
preload-icons.tsclient-side before Svelte components initialize (for removing CDN)document.querySelectorrequestAnimationFrame, recalculate cached thresholdssrc/components/widget/Profile.astro:
BrandIcon.sveltefor social link icons (enables CDN loading for dynamic brand icons while keeping astro-icon for static icons)tailwind.config.cjs:
hoverOnlyWhenSupported: true to prevent sticky hover states on touch devicesHow To Test
Use lighthouse test service to test:
https://pagespeed.web.dev/
Remember to turn on brotli/gzip compression, and make sure the blog contains sufficient content for testing.
Screenshots (if applicable)
Details
Before:


After:


Details
Before:After:


Additional Notes
scripts/get-icon-data.jsis the script that helps users obtain icons if they want to embed them, or provides developers with references to the icon SVGs.Reason to eliminate bundled icons
I specifically decide to move all icons for social links to CDN.Currently, the size of

/_astro/Icon.xxxx.jsis 70+ KB (deflate) / 11 KB (brotli).As we cannot predict how many icons the user will add, so I choose to only embed 6 icons which are hard-coded. For other requests, redirect them to CDN requests (with DNS prefetch).
After this change, the size become: 3.14 KB (deflate) / 0.1 KB (brotli).
Considered the file size is significantly reduced, this approach should be under consideration.
Chores
I was wondering why my blog was loading slower compared to others for a very long time, even though I am using the same template.
I compared some forks and blogs that use this template, and I found that most of the issues are due to the number of characters (not words) in each article being too high. This exacerbates the potential issues within this template.
I like this template, so I have no choice but to address the issue.
After fixing the animation reload issue (#720), the blog visually loads much faster, even though it doesn't have a high score in Lighthouse. This PR is the further improvement specifically for lighthouse testing.
If your blog does not contain many words in each article, there is no need to implement this PR. Visual improvement is not significant in this PR.
Missing banner
I was curious why banner is missing in my output, but looks like it is missing in current version (not due to my change): #681 (comment)
Click preview link, and you can find out that the banner is already missing in official build.

Upgrade to v6
Very interesting, after upgrading to v6.0.0-beta.6, the score is higher:


I have never seen a score of 99 on my blog. (and score for mobile is increased too)