零加载时间的幻觉

1作者: AliceHe20036 个月前
去年夏天,我开始通过一个名为“奥丁计划”的在线课程学习 Web 开发。随着我对 Web 标准和用户界面设计越来越熟悉,我决定构建一些属于自己的东西:我自己的网站。 作为一个在 Instagram、YouTube、TikTok 和 Snapchat 上拥有超过 100 万粉丝,每月观看量超过 1000 万的创作者,我希望有一个真正反映我自己的网站。最终呈现的是一个 4 页的网站,包括主页、关于我、作品集和赞助商信息。 我最喜欢的部分之一是作品集页面,我使用视差效果来展示我的艺术作品。但一开始,我遇到了一个主要的性能问题:页面需要大约 30 秒才能完全加载。Lighthouse 给我的性能评分约为 20%。 经过一番调查,我意识到问题所在——PNG 文件太多且过大。我将它们转换为 WebP,这是一种现代图像格式,使用更好的压缩方式,同时将质量损失降到最低。这使我的评分提高到大约 50%,但加载时间仍然很明显。 所以我进行了进一步的优化。我使用 React 中的“useEffects”钩子在主页加载后预加载所有 WebP 图像对象。由于大多数流量都是通过主页进入的(在我的社交媒体简介中链接),这种优化确保了用户到达作品集时图像已经准备就绪。 结果呢?Lighthouse 评分超过 90%,图像渲染几乎瞬间完成。 在这里查看:https://artbyaalice.netlify.app/
查看原文
Last summer, I started learning web development through an online course called The Odin Project. As I got more comfortable with web standards and user interface design, I decided to build something personal: my own website.<p>As a content creator with over 1 million followers across Instagram, YouTube, TikTok, and Snapchat, and over 10 million monthly views, I wanted a site that truly reflected who I am. The result is a 4-page website featuring a homepage, about me, portfolio, and sponsor info.<p>One of my favorite parts is the portfolio page, where I showcase my artwork using a parallax effect. But early on, I ran into a major performance problem: the page took ~30 seconds to fully load. Lighthouse was giving me a performance score of ~20%.<p>After some digging, I realized the issue—too many large PNG files. I converted them to WebP, a modern image format that uses better compression with minimal quality loss. This brought my score up to ~50%, but load times were still noticeable.<p>So I optimized further. I used the “useEffects” hook in React to pre-load all WebP image objects after the homepage loads. Since most traffic enters through the homepage (linked in my social bios), this optimization ensured that images would be ready by the time users reached the portfolio.<p>The result? Lighthouse score over 90%, and near-instant image rendering<p>Check it out here: https:&#x2F;&#x2F;artbyaalice.netlify.app&#x2F;