11 ms·
There are a few more things that help: - Reducing DNS calls and server round trips. Loading fewer resources from fewer domains makes a huge difference. Using s
by nicbou 5y ago
There are a few more things that help:
- Reducing DNS calls and server round trips. Loading fewer resources from fewer domains makes a huge difference. Using server push also helps, although it might get deprecated.
- Responsive images. Load small images on small displays. Don't load 2x images on lower density displays.
- Using the right load event for JavaScript. load fires long after DOMContentLoaded on some pages, especially on slow connections.
- Setting the size of elements before they load, to prevent the content from jumping all over the place.
- Loading fewer fonts, and serving them yourself. Google Fonts is significantly slower.
- Gzipping everything you send. It makes a significant difference on slow connections.
- Static caching. This will shave whole seconds off your page load time. Cache both on the server and in the browser, but mostly on the server.
- Consider perceived performance too. It doesn't matter how fast you force a coercive cookie notice on your readers.
- Performance extends to the content of the page. Don't make users chase answers. Give clear, concise information and use typography to guide your users to it.
- musicale 5y agoAlso: - get rid of bloated adtech (e.g. 6MB of adtech garbage from 60 domains for 20KB of text) - remove all popups, slideovers, mailing list signup garbage, etc. - get rid of autoloading/autoplaying video - avoid bloated frameworks - avoid external fonts
- hermitdev 5y ago> Setting the size of elements before they load, to prevent the content from jumping all over the place. This is especially jarring on a phone. Multiple times a day, I see this, and it pisses me off each and every time. Nothing like reading an article to all of a sudden have some image load somewhere (likely not even visible on screen) suddenly cause what you're reading to disappear off screen. And I'm not on a slow connection, either. I'm typically on uncongested wifi connected to fiber when at home, 5G otherwise. JavaScript in general is so bad, or rather is being used for so many bad practices, that I've disabled it on my main mobile browser. What little good it's used for doesn't out weigh all of the bad out there. I'm tired of malicious ads hijacking the page, either rendering popups or redirecting me somewhere I don't want to go. If a site doesn't render anything useful without javascript (Twitter is a prime example), I typically turn around and go elsewhere.
- tshaddox 5y agoLayout shift due to responsive images is now easy to prevent, because most up-to-date browsers now correctly set the aspect ratio of a responsive img element if you add the height and width attributes. Before a year or so ago, you had to use hacks like padding percentages to correctly set the aspect ratio. https://www.smashingmagazine.com/2020/03/setting-height-width-images-important-again/ https://www.smashingmagazine.com/2020/03/setting-height-widt...
- sirshmooey 5y agoYou can automate this in VSCode, very handy. https://christianheilmann.com/2021/04/14/quick-vs-code-tip-automatically-add-image-width-and-height-to-images/ https://christianheilmann.com/2021/04/14/quick-vs-code-tip-a...
- dredmorbius 5y agoDepends. There are extensions (Dark Reader, a dark/light mode extension for Firefox, is an example) which trigger multiple redraws of a page on load. On an e-ink device (my principle driver these days), the extension is a near necessity (ironically, to force black-on-white themes on sites, much more readable on e-ink), and page re-paints are all the more jarring and expensive. Simple pages still load quickly and without disruption. Many complex sites don't. (NPR's website comes particularly to mind.)
- Arrath 5y ago> This is especially jarring on a phone. Multiple times a day, I see this, and it pisses me off each and every time. Nothing like reading an article to all of a sudden have some image load somewhere (likely not even visible on screen) suddenly cause what you're reading to disappear off screen. This is the worst on picture rich recipe blogs. I hate it.
- pdenton 5y agoNothing saves as much as just writing the HTML, CSS, and JS by hand. No build step or anything but an editor. No need to minify anything, keeping it nice and simple. Responsive images are kind of funny in the sense that my webpages are nearly twice the size on mobile vs my laptop. The screen may be smaller, but the CSS pixel ratio is 1 on my laptop vs 3 on an iPhone.
- vore 5y agoI think a lot of the suggestions the parent comment suggests are orders of magnitude better savings than writing things by hand... Perhaps writing things by hand has a questionable nostalgic allure of "keeping one honest" but beyond that I don't think it's super practical.
- Nextgrid 5y agoWhile true in theory, I believe that keeping things handmade means that the payload couldn't realistically become big enough for the parent's suggested optimizations to actually matter. An unoptimized payload isn't that big of a deal if it's still smaller than the best optimized one.
- vore 5y agoPerhaps not all of the advice applies, but when it comes to images and fonts, I don't think any amount of keeping things handmade is going to outstrip the advice regarding static caching and loading fewer fonts.
- bachmeier 5y agoThe best advice for images is to delete them. There's a widespread belief that meaningless pictures at the top of a post are critical. Here's the first link that comes up on Medium: https://equinox-launch.medium.com/trade-hard-win-big-dopewarz-has-landed-3240e4705b97 https://equinox-launch.medium.com/trade-hard-win-big-dopewar... The value added of that image at the top is negative. This is, sadly, the rule rather than the exception. Edit: This is an even better example: https://medium.com/general_knowledge/top-10-crypto-gaming-projects-bonus-612249019a5e https://medium.com/general_knowledge/top-10-crypto-gaming-pr... How anyone can look at that image and say "that'd be perfect for the top of my next post" is beyond me.
- berkut 5y agoOn a semi-related note: Is there any chance in the future that browsers are going to support / implement lazy-loading of images themselves (i.e. based off what's visible in the viewport). Currently you have to (as far as I'm aware anyway, but I'm only just getting re-acquainted with web-dev) use JS to do it (things like LazySizes), which adds complexity, and is even more complicated if you want to combine that with responsive images... Or am I missing something that's possible already?
- benhoyt 5y agoYou can set the attribute loading="lazy" on an <img> tag and the browser will do it for you. Looks like Edge and Chrome and Firefox support it, but not Safari yet (https://caniuse.com/?search=loading https://caniuse.com/?search=loading).
- aimor 5y ago"Setting the size of elements before they load" I host a personal photo gallery online and I've been dreading implementing this for images to get rid of the jump when lazy loading. I'm not even sure there's a good way to do it.
- bigyikes 5y agoFor my personal image gallery, I have a script to include the image dimensions in the file name when I upload. It’s kind of a hack, but it lets me compute the final image flow based on the file name before any of the images have loaded.
- mikeiz404 5y agoDo your photos scale in your gallery? This is off the top of my head but if your images are set to a percent based width so they scale (mine are) and you know the aspect ratio of the image then you can set the CSS ‘ aspect-ratio’ property (or there are some other hacks with padding on a wrapper div) to maintain the height. You’d probably want to integrate this into the build process but I have not done this.
- tshaddox 5y agoYou don't even need the recently-added aspect-ratio property. In most up-to-date browsers you can now just add the height and width attributes to the img tag and the aspect ratio will render correctly even for responsive images: https://www.smashingmagazine.com/2020/03/setting-height-width-images-important-again/ https://www.smashingmagazine.com/2020/03/setting-height-widt...
- mceachen 5y agoThe only way to prevent reflow is to give the browser your image dimensions or aspect ratio: https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-rati... Using a css flexbox or grid layout means you don't have to recalculate image div widths and heights when the browser viewport width changes, but you still need to give it enough information to back into the correct aspect ratio. Also, using a srcset helps only load the necessary bytes, but means you'll need to either build the resized image on the fly (which is cpu-expensive) or prebuild them (which takes up some disk space). In the interests of a performant UI, PhotoStructure extracts and remembers width and height of photos and videos during imports, but if you're only loading a couple images in a gallery, your could fetch this metadata on the fly as well.
- jcun4128 5y agoside note: why is it an iPhone with a crazy looking display is only 300 and some pixels wide viewport in the web, that seems odd. I did check on my Android and it's similar, 1080P display but 412px wide in browser also that bottom navbar in Safari ahh
- deergomoo 5y agoIt’s points, not pixels. A modern smartphone usually has a scale factor of 2 or 3, giving the same logical screen space with a significantly sharper image.
- sp332 5y agoA point is 1/72 of an inch. A CSS pixel is canonically 1/96 of an inch. https://developer.mozilla.org/en-US/docs/Glossary/CSS_pixel https://developer.mozilla.org/en-US/docs/Glossary/CSS_pixel
- eyelidlessness 5y agoIt's not (as sibling comment says) points, it's logical pixels as declared by the device/user agent's pixel density. Device pixels are usually (but not always) some integer multiple of the logical pixels.
- ravenstine 5y ago> Loading fewer fonts, and serving them yourself. How about no serving of fonts? I don't think I've ever looked at a webpage and thought it would be improved by a particular font family. What exactly can't be accomplished with standard web fonts? Icons? Haha, don't even go there.
- nicbou 5y agoIn my case it guarantees a certain level of readability that is consistent across platforms. I spent quite a bit of time fine tuning the font weights to help readability. That costs about 60 kb, so it's hardly a huge sacrifice.
- lazyjeff 5y agoAbsolutely, especially with the recent "invention" of the native font stack as a solution that does not require loading external files while showing a nice modern font. Imagine if the trade-off was more explicit to the visitors: would you want something that made your web browsing slower, your text flashes in like a cheap powerpoint slide, and sent your data to Google, in exchange for being able to read in a different font? External web fonts are purely for the ego of the web developer, not for the reader.
- shakna 5y agoI actually disabled loading of webfonts. The only two websites I've encountered where I actually notice it, and remember that I did that, is Google Translate and a particular government website I use about once a year. Everything, everywhere else, seems to work just fine with using the browser defaults.
- ratww 5y ago> The only two websites I've encountered where I actually notice it, and remember that I did that, is Google Translate and a particular government website I use about once a year. That's probably because of the Google Material Icons font, I believe? It shows or used to show text instead of icons when it couldn't load.
- Semiapies 5y agoA number of those are in TFA.
- deleted 5y ago[deleted]
- Seirdy 5y agoServer push has been deprecated by browsers for a while now. To reduce round-trips, consider using TCP Fast Open and 0-RTT with TLS 1.3. Note that 0-RTT can enable replay attacks, so I'd only consider using it for static content. HTTP/3 and QUIC has improved support for 0-RTT. Gzip is good for dynamic compression, especially with zlib-ng. For static compression, I'd rather use Brotli.