WordPress fallback for Bootstrap's CDN without relying on JavaScript?
After the first time the php script tries accessing the CSS file, the server returns a status code 304. The easiest implementation to check for this would be the following:
function bootstrap_css() {$bootstrap_cdn = 'https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css';$cdn_check = @get_headers($bootstrap_cdn);if (strpos($cdn_check[0], "200") !== false || strpos($cdn_check[0], "304") !== false) : wp_enqueue_style('bootstrap',$bootstrap_cdn,array(),'4.2.1');function add_cross_origin($html,$handle) { if ('bootstrap' === $handle) { return str_replace("media='all'","media='all' integrity='sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS' crossorigin='anonymous'",$html); } return $html; }add_filter('style_loader_tag','add_cross_origin',10,2); else : wp_enqueue_style('bootstrap',get_site_url() . '/css/bootstrap.min.css',false,'4.2.1'); endif;}add_action('wp_enqueue_scripts','bootstrap_css');