Recommendations for maintaining assets across domains?

My webserver file system is equivalent to the following:

/master-domain.tld /master-domain.tld/assets/js/foo.js /master-domain.tld/assets/css/bar.css /sub1.master-domain.tld /sub1.master-domain.tld/assets/js/foo.js /sub2.master-domain.tld /sub1.master-domain.tld/assets/css/bar.css ... 

What I would like to know is how to maintain my common static assets (hosted in the main domain) for my subdomains - the reason is that I only need to maintain one set of β€œcore” assets then, and not update / copy any files to all other subdomains every time I edit them. Obviously this can be achieved using absolute URLs, but my goal is to avoid them, so that my local / dev system does not need any remote calls during development / debugging.

I currently have a mod_rewrite + symlink + php script configured for each subdomain, linking any calls with non-existent local assets to the main assets. for example, calling "/sub1.master-domain.tld/assets/css/bar.css" will retrieve the bar.css file hosted in the main domain because the local version of bar.css does not exist. In addition, calling "/sub1.master-domain.tld/assets/js/foo.js" will serve the local version of foo.js as it exists.

But my current method seems to interfere with the loading performance of my page, and I wonder if there is a more efficient (still modular) approach to solving this problem.

Any tips? Am I really not quite right about this?

+4
source share
3 answers

Symbolic links should be all that is required if they are all on the same server. This should not result in poor performance. For instance.

 /sub1.master-domain.tld/assets -> /master-domain.tld/assets 

If your subdomains are served from multiple servers, I would set the mod_rewrite rule with 302 redirects to the full URL of the main domain. On this master server, I would set mod_expires so that the assets are cached, avoiding most subsequent requests for the same β€œmissing” assets on subdomains.

+1
source

If they are on the same machine, why not point the different virtual host aliases to the same document root?

0
source

I would use a reserved static file. subdomain for this purpose and target all requests to it.

0
source

All Articles