javascript - Use local css file if link to online css file is dead -
the problem:
i using w3.css(if enter w3schools.com
site down maintenance) styling website.the problem here w3schools.com
going down times times.
then website looks creepy , don't need that.
so have local copy of w3.css
on computer , server holding website.
online:
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
local:
<link rel="stylesheet" href="../css/w3.css">
the question:
how know when link pointing on w3schools
dead,so can use local w3.css
file.how can that?
1)detect if broken
2)use local css before website has been loaded
finally
what big companies doing that?if 3-4
webservices go down whole company going down.....
i new web developing so..thank you...
edit:(i have in mind)
loading local(...site in on server,that local mean)
, w3schools
file , increase site loading...
its possible php. haven't tested should work.
put inside <head>
tag.
<?php if (isdomainavailible('http://www.w3schools.com')){ echo '<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">'; } else { echo '<link rel="stylesheet" href="../css/w3.css">'; } //returns true, if domain availible, false if not function isdomainavailible($domain) { //check, if valid url provided if(!filter_var($domain, filter_validate_url)) { return false; } //initialize curl $curlinit = curl_init($domain); curl_setopt($curlinit,curlopt_connecttimeout,10); curl_setopt($curlinit,curlopt_header,true); curl_setopt($curlinit,curlopt_nobody,true); curl_setopt($curlinit,curlopt_returntransfer,true); //get answer $response = curl_exec($curlinit); curl_close($curlinit); if ($response) return true; return false; } ?>
reference: https://css-tricks.com/snippets/php/check-if-website-is-available/
Comments
Post a Comment