DEV Community

Eliminate render-blocking resources

Olimpio on September 25, 2018

The audits tells me to Eliminate render-blocking resources and its giving me the cdn link of bootstrap... And I don't know how to deal with it.... Can you help?

Collapse
 
ben profile image
Ben Halpern

I've written about this a bit

And discussed it in a Railsconf talk

Good luck! This may not be worth worrying about, and things like HTTP2 server push may be making this less approach obsolete, but in case you want to learn more, I hope my resources help.

Collapse
 
rnrnshn profile image
Olimpio

Thank you... Great tips. I didn't know about cloudinary and I'm testing it and it just amazing... About eliminating CDN links it's kinda confusing cuz back in time many devz were recommending to use CDN "cuz it was fast and secure and bla bla bla" but things are changing now... 😉

Collapse
 
ben profile image
Ben Halpern

I think there's some nuance there, CDNs are still pretty amazing as a technology itself.

But yeah, don't want to be doing things willy nilly. You're introducing some chaos every time you do.

Collapse
 
equinusocio profile image
Mattia Astorino • Edited
<link rel="preload" href="style.css" as="style">
<link rel="preload" href="main.js" as="script">

developer.mozilla.org/en-US/docs/W...

The preload value of the element's rel attribute allows you to write declarative fetch requests in your HTML

, specifying resources that your pages will need very soon after loading, which you therefore want to start preloading early in the lifecycle of a page load, before the browser's main rendering machinery kicks in. This ensures that they are made available earlier and are less likely to block the page's first render, leading to performance improvements. This article provides a basic guide to how preload works.

You can't use defer or async because if you load an ui component that require js at the top of the page you must already have his js working.

Collapse
 
rnrnshn profile image
Olimpio

Ohhhh... This will be hepful when using Google fonts/... Its very interesting... Thank You

Collapse
 
bennypowers profile image
Benny Powers 🇮🇱🇨🇦

What I've done in the past is use a chrome extension called Used CSS to generate a stylesheet which only contains the used css rules.

Collapse
 
rnrnshn profile image
Olimpio

Ohhh. Thank you... But how will I remove unused CSS rules which are inside the file on the CDN link?

Collapse
 
bennypowers profile image
Benny Powers 🇮🇱🇨🇦

I just deleted the CDN link and only used my generated CSS.
Just be careful with this technique because if you later on need to use bootstrap styles that weren't included, you'll be out of luck.

Collapse
 
edisonywh profile image
Edison Yap

Are you loading it async?

Collapse
 
rnrnshn profile image
Olimpio

Actually used the CDN link on the head tag... I guess it's sync...

Collapse
 
edisonywh profile image
Edison Yap

One way I can think of is that you can use JS to load the stylesheet asynchronously.

stackoverflow.com/questions/240202...

What Render Blocking means is that on your initial load, the browser is waiting for all resources to be fetched. There's a couple ways to defer loading, I think JS have a simple async='true', whereas CSS is a bit trickier. The link I shared has better information.

Thread Thread
 
rnrnshn profile image
Olimpio

Thank you... I will read it carefully

Collapse
 
rhymes profile image
rhymes • Edited

async and defer should help alligator.io/html/defer-async/

Collapse
 
rnrnshn profile image
Olimpio

Lemme try