Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mayeenulislam/d0ac320973e9189fe559 to your computer and use it in GitHub Desktop.
Save mayeenulislam/d0ac320973e9189fe559 to your computer and use it in GitHub Desktop.
Check the latest jQuery library from the server. If fails, load the library from the local directory.
<?php
/**
* According to the lhrec_106's answer at StackOverflow
* http://stackoverflow.com/a/17339542/1743124
*/
$jQueryLatestURI = "http://code.jquery.com/jquery-latest.min.js";
@$connection = fopen( $jQueryLatestURI, "r" );
/**
* FALLBACK
* Check whether the jQuery library from server is available or not
* If available, load from server,
* If not, load from the local 'js' directory
*/
if($connection) {
/* Latest jQuery Library from Server */
<script type='text/javascript' src='<?php echo $jQueryLatestURI; ?>'></script>
} else {
/* In-Package jQuery Library */
<script type='text/javascript' src='js/jquery.js'></script>
} //endif($connection)
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment