I would prefer require(…) instead of include because if the style-sheet is missing then PHP errors will be activated which should show in your PHP error log file…
I think there are a couple of factors to consider.
If the style-sheet size is small and less than about 4Kb it would be advantageous to include/require the style sheet in order to minimise an additional HTTP request.
Another factor is the site’s bounce rate. If it is high then there is little advantage gained by using the link method for subsequent pages.
Unless the person is creating an AMP page which requires inline css Doing it this way would allow you to have a single stylesheet for easy editing but still create the necessary inline markup for AMP. (unless i’ve misread what is needed for AMP).
Are we talking about Google’s PageSpeed Insights?
It is only a tool. It is telling you what you can save. You don’t have to do anything the site suggests. They are only suggestions. Some are helpful, others are nonsense. I had one page where it told me I could save 1 Byte!!
Hi,
its a new(ish) way of marking up a webpage to make it the more mobile friendly and fast It has certain differences to a standard webpage including making all of the css inline (ie you don’t call in any external css files). I forgot the syntax is slightly different which @John_Betong has corrected above. But it was just an example of where you might be better using php to insert css from another file.
So for a 15k CSS file not using AMP that would definitely be the preferred alternative. (unless the styles.css file itself contains PHP in which case you’r rename the file as styles.php and have it serve the appropriate CSS MIME type header so that the file is recognised as CSS).
The speed difference is very small and you would need a very busy site to notice it.
Do not use require_once - _once makes no sense in this case, it doesn’t really hurt but adds a microscopic overhead.
The biggest speed difference will be if you use an opcode cache (opcache) on your server (which is always a good idea!). require and include will be picked and compiled by the cache so in practice the external file will not really be loaded after the php code has been cached in memory. file_get_contents, on the other hand, will have to be executed every time.
I would still prefer linking in html like @Gandalf suggested.