Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this way of internal CSS valid?

I am trying to optimize a small website, I am now looking into the CSS.

Let's take the example of index.php. I have first done it the standard way by adding <link rel="stylesheet" href="style.css"> in the <head> of my HTML output.

Google PageSpeeds then complains about the render-blocking files.

I then tried an alternative way and instead of the <link> tag above, I added this in the <head> :

<style>
    <?php include 'style.css';?>
</style>

This effectively gives me an internal CSS while still having the convenience of having one file for all my pages. I do not have render blocking files anymore and PageSpeed seems happier.

Is there any significant drawback here? Should I be as happier as Google PageSpeed is?

like image 646
Memes Avatar asked Sep 19 '18 04:09

Memes


1 Answers

Google's documentation for optimizing CSS delivery suggests only inlining small amounts of critical CSS. You'll find that caching techniques can reduce the parsing time required for including your CSS file. There will be a sweet spot where it's worth the maintenance cost.

You could look at installing the Page Speed module as well. Some more articles about PHP caching are below. You might also look at enabling compression for your static file transfers - that reduces the size for most text files significantly.

  • https://secure.php.net/manual/en/book.apc.php

  • https://medium.com/@dylanwenzlau/500x-faster-caching-than-redis-memcache-apc-in-php-hhvm-dcd26e8447ad

  • https://pantheon.io/docs/alternative-php-cache/

like image 193
Will Bickford Avatar answered Nov 11 '22 12:11

Will Bickford