As you know, uploading css-styles and JavaScript-code from third-party services allows you to reduce the size of the site and thereby increase speed. For example:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 

Question: Is it possible to achieve the same effect of reducing the size of the site, if you also store your own styles and JS-code in a separate domain?

For example, instead of storing styles in a site directory on a hosting, as they usually do:

 <link href="css/style.css" rel="stylesheet" type="text/css"> 

we buy another domain, upload only css- and js- (and nothing more), and connect to our main site:

 <link href="domain-name.ru/css/style.css" rel="stylesheet" type="text/css"> 

This will probably make sense in particular when two different sites have common styles.

  • Moreover, each individual file must be stored on a dedicated server. - Sergey
  • Interesting ... And you can constructively justify? - Bokov Gleb
  • Derived by the method of mathematical deduction. Heard from this? If something is true for two cases, then it is suitable for all others. Scattered over the domains of scripts and styles, it turned out nishtyak. So, scattering all files across domains, we will get even more nishtyakov. - Sergey
  • And if you need less nishtyakov, then two servers will be enough? Okay, the next message you will not answer, but they can spank for flood. - Bokov Gleb
  • One server is enough, someone already wrote the correct answer. - Sergey

1 answer 1

If a site with js and css content is not available on all other sites, you will get broken pages, plus the inconvenience of development and plus troubles with an additional domain and hosting. if you consider such sacrifices justified for several hundred kilobytes, then web technology allows you to do this and has the right to exist.

  • Additional hosting is not necessary - the main thing is that the domains are different. Some hosting offer the service "multidomain". So you can load some css and js into one domain account (the same jquery or cross browser css styles) and connect to other sites. What do you think about this particular case? - Hokov Gleb
  • @GurebuBokofu, and then what's the point of doing this if the physical file system is the same? There will be no acceleration, and you will be kilometer-long to your files in the code. what's the convenience. But problems due to the MX domain settings can lead to the inaccessibility of such paths. - perfect
  • Suppose you have created accounts on abc.com and xyz.com on some hosting; each has its own domain folder, each has its own styles and js-codes. If I go to abc.com, then my output to the browser will be only from the files of the abc.com folder, without affecting the files from xyz.com, right? And now let's say that abc.com and xyz.com use the same styles. I create another common.com domain on the same hosting and upload common css-styles to the folder with this domain and connect them to both abc.com and xyz.com. Thus, there is no need to duplicate the code on two sites + each site weighs less. - Bokov Gleb
  • @GurebuBokofu, 1) js and css weigh very little and it is not logical to buy (consider and renewal) a domain for 5 megabytes. 2) let's say you have a situation that the style should be a little different from the main one, what will you do? 3) what does not change from time to time and is so available on host hosting (for example, jquery library) 4) if your method were as good as you imagine it has been used by everyone for a long time, and everyone uses simple copying of files from one place to another . Simply put, you do not have a file storage and not worth the candle. - perfect
  • 1) I agree. 2) I will redefine styles over previously defined ones. 3) What if I wrote a number of general-purpose JS functions and use them regularly? If I want to refactor them, then on all sites where these functions are connected, I will also have to insert a new code. 4) Well, the first drawback is the need to buy a new domain and renew it. I have two questions: 1. What else are the disadvantages? 2. Provided that the hosting is good, will the storage on the selected domain give styles and js a reduction in the size of the site and due to this speed? - Lateral Gleb