32
loading...
This website collects cookies to deliver better user experience
A snappy user experience beats a glamorous one, for the simple reason that people engage more with a site when they can move freely and focus on the content instead of on their endless wait.
script
tags. Like CSS, the browser dispatches a request to download the javascript file immediately but, instead of continuing the HTML parsing, it pauses until the javascript is downloaded and executed.style
tag can be used to inline these rules directly into the HTML file. This will void a second network round trip by the browser to fetch the critical CSS. As an effect, the page rendering process won't be blocked by CSS download and the above the fold can be rendered much faster.link
tag to a CSS resource will cause the browser to pause the render process until all the CSS is downloaded and parsed.window.onload = () => {
const link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('href', 'path/to/noncritical.css');
document.head.appendChild(link);
}
onload
event. This is required to make sure that the initial page has been completely rendered before the non critical CSS is inserted, avoiding this new CSS to block the initial render.script
tag supports two attributes that are useful to load scripts without blocking the HTML parser. These attributes are async
and defer
.defer
are executed only after the HTML parsing is done. For this reason, defer
scripts won't block parsing.Async
scripts, on the other hand, are executed as soon as they are available. If the browser finishes downloading an async
script while the HTML is being parsed, it will pause the parsing to execute the script.defer
should be preferred over async
to load javascript.as
attribute:<link rel="preload" href="style.css" as="style">
gzip
and brotli
compression. It's also easy to find tools to allow your server to compress files before sending them to the browser.url()
or a block of text.32