Perhaps the question is rather stupid, but I did not find a direct answer in the articles.

As we know, one css file with all styles is connected to the site (ideally).

However, there is such a situation (in a vacuum):

Suppose there are two sites on the same domain (which is stupid). We go to the main, there are two links: site1 and site2. The structure is as follows:

/index.html - это наша главная /site1/index.html - сайт 1 /site1/style.css - стили сайта 1 /site2/index.html - сайт 2 /site2/index.css - стили сайта 2 

Addresses are different, it is obvious. We constantly work only with site 1. Accordingly, its css styles are stored in the cache. And suddenly we visited the site 2.

What happens in the cache?

  1. Site styles 2 will replace site styles 1 (because the domain is one)?
  2. Styles site 2 will be next to the styles of site 1 (because the addresses are different)?

If situation 1, then how to be, if the sites are not 2, but much more, and if you shove everything into one css, then it will weigh very, very much (and we don’t need all the styles, if we use only site 1 )?

If situation 2, then it turns out that it is beneficial to connect those styles that are relevant to a particular page, because Each page has its own address. But we are trying to connect as few css-files as possible, does this mean that only situation 1 is possible?

Will the result change if you use CNC and a single entry point (as far as I understand the single entry point, the address is always the same, but the page is built depending on the $_GET variables)?

PS I hope that explained the question quite clearly. Thanks in advance for the answer (s).

    1 answer 1

    There will be a situation 2

    Browser caches files by full url before file
    For example http://site.com/css/main.css this file will be cached

    The second situation you wrote incorrectly.
    The browser caches styles not for a specific page of the site, but by the full url before the file with styles.

    Therefore, there is such a thing as CDN-hosting libraries

    If you have noticed, the source code sometimes contains the entry http://site.com/css/main.css?v4
    So reset the previous cache to reset the current will need to write http://site.com/css/main.css?v5

    If you configure nginx with expires -1 for css, then the browser does not cache your style file

    • If I understand you correctly, then you need to do this: each of the sites has its own style file (they will become parallel), but only one is connected inside the site, because the browser caches "full url before the style file", right? - FLighter
    • Well, if different sites use different styles, then in the index.html of each site you register your own style file - OotzlyGootzly
    • one
      Thank you. The answer is more than clear, thanks - FLighter