Home > Enterprise >  CSS Generic vs Page Specific loading
CSS Generic vs Page Specific loading

Time:12-04

I need some advice on CSS placements for the sake of website load times

I read that it's best to have 'critical CSS' in the head and the rest can be placed in their respective page's body via the tag.

Is it good practice if I loaded all the CSS or at least the 'Generic' styles that many pages share while I kept page specific styles in a tag in the page's body?

One side question, some of my pages use jQuery, should I only load that at the bottom of those pages or leave it in the template head?

I tried both and the site loads just fine, but I know under the hood results may vary. I'm not sure how to even check. I tried websites that test a website's load performance and I got mixed results. So I'm not sure how to optimize my website's performance.

CodePudding user response:

Usually all CSS files are called in the head, one thing you can do to improve performance is to modularize, let's say that you have the global styles in one file called global.css and it contains your font specs, global components used in all pages such as navbar, footer, layouts, etc... And in another file you can only put the styles regarding your specified page such as contact section that's another page called contact.css and there you can have overrides to global file and specific styles that you only use in this page.

This way you can serve less heavy files regarding the page that user's requiring.

Regarding you jQuery question I suggest that don't load jQuery library if you're not using it, it's useless. Only load it in the pages that you're using the library. Hope it helps!

  • Related