Including a single javascript file on multiple domains
I have multiple domains with multiple copies of jQuery.js in separate subfolders. I want to consolidate them so there's only one, and so there's no reference in one domain to another so I can use the same one fo开发者_运维技巧r work and personal.
Furthermore, I don't want to use symbolic links because I'll be moving servers sometime this year and I feel that a lot of symlinks could complicate things. One idea I had was instead of this in the HTML:
<script src="js/jquery.min.js" type="text/javascript"></script>
to do this:
<script src="jquery_min_js.php" type="text/javascript"></script>
And that file will look like this:
<?php echo '/home/path/to/js_files/js/jquery.min.js' ?>
Is there a smarter way to do this? I'd like to somehow make a function so like
<script src="get_javascript.php?script=jquery_min_js" type="text/javascript"></script>
and then get_javascript.php might look like:
<?php echo '/home/path/to/js_files/js/'.str_replace('_','.',$_GET['script']).'.js' ?>
Am I barking up the wrong tree? Am I even in the right forest?
One idea is to include from google code:
<script type="text/javascript src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
3 reasons why:
http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/
You can link to jQuery from either Google or Microsoft.
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js"></script>
or
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js">`</script>
精彩评论