Search code examples
javascriptphpjquerycssstylesheet

Switching From Online to Offline Stylesheets Based on Internet Availability


Question / Problem: Is it possible to automatically switch between online stylesheet to offline stylesheets?

For example, here in the office whenever I developed a site I need to connect to live bootstrap stylesheet, but whenever I go home I need offline stylesheet. I'm tired of commenting the stylesheets to be used. Is there any way?

Conclusion: Thanks to all, by using the code of linkinTED I've solved this problem of mine.


Solution

  • Based on your comment, that you are able to use PHP, you could use this code:

    <?php
    
    $extUrl = 'http://www.somesite.com/stylesheet.css';
    $intUrl = 'css/stylesheet.css';
    
    $url = ( @fopen( $extUrl, "r" ) ) ? $extUrl: $intUrl;
    
    echo '<link rel="stylesheet" href="' . $url . '" />';
    
    ?>