Say I have the following structure for 3 different apps that live on 3 different domains, and a personal “cdn” where I can put files that are common across all three apps:
root/
/dinosaureggs.com
/magicalapples.com
/wizardsupplies.com
/mypersonalcdn.com
/js
/php
/css
This same structure is mirrored on a local and production environment.
If I’m in dinosaureggs.com and I want to use a shared PHP library in the /php folder I can say:
require('/../mypersonalcdn.com/php/library.php')
This works fine on both the local and production servers.
However, it won’t work for JS because JS includes can’t back out of the “app” with paths the same way PHP can.
I can’t say:
<script type="text/javascript" src="/../mypersonal.cdn/js/library.js"></script>
Now, on live I could say:
<script type="text/javascript" src="http://mypersonalcdn.com/js/menus.js"></script>
But this doesn’t solve my problem for local environment (at least to the extent that I wish to leave it truly locally and have the option to develop offline).
Any suggestions?
While the PHP to fetch JS method above was ok, this was a much more straightforward solution that I eventually landed on:
Serving files outside of doc root / having common client files across multiple domains
To do this you set a mod_alias in http.conf
On local environment that looked like this:
This makes it so you can call a css (or image or js or whatever) like this:
But instead of looking in /shared/ on that domain, it’d go to wherever on the server you had “shared” pointed to; in this case: /Users/Jane Doe/Sites/shared/
Resources: