Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are entire websites automatically cached (Google using <style>)?

I've heard of stylesheets being cached, but are regular pages (like the one we're on) cached? I noticed on the more recent websites Google has made, they are not even using stylesheets, just a <style> tag with a single, compressed line of CSS. This led me to believe that the entire page (including the <style>) is cached, and not just stylesheets. Am I correct on this? Why would Google not use stylesheets and want their CSS to be cached when their sites are viewed billions of times a month.

From my understanding, everything that appears in the "Network Panel" of Chrome's inspect element is cached?

I researched "PHP Caching" but that seems to be for include's, so I'm guessing pages are already cached automatically.


2 Answers

Check this post: CACHING TUTORIAL.

Use <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> tag in your <head/> section. Use headers in your PHP code:

<?php
 Header("Cache-Control: must-revalidate");
 $offset = 60 * 60 * 24 * 3;
 $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
 Header($ExpStr);
?>
like image 104
Arthur Halma Avatar answered Dec 23 '25 14:12

Arthur Halma


Caching is about resources corresponding to individual URLs, not about sites. Basically, resources of all kinds, like HTML documents, images, style sheets, JavaScript code, plain texts etc. etc. can be cached. So a site as an entity is not cached, and neither is a “whole page” (HTML document + images used in it + stylesheets it refers to +...). But each component may be cached, under its own URL.

Google uses embedded style elements for some very short style sheets, probably because they think this is more efficient than using an external CSS file. The HTML document may well be cached, but even if it is not, their approach is a little bit faster than using an external style sheet, which may cause HTTP overhead.

But for any nontrivial CSS code that you use on different pages of your site, an external CSS file is more efficient. It will be loaded (with small HTTP overhead) when a user first visits your site, but when he moves around it, the browser will have the CSS code in its own cache.

like image 31
Jukka K. Korpela Avatar answered Dec 23 '25 13:12

Jukka K. Korpela



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!