Sharing CSS stylesheets across different domains Sharing CSS stylesheets across different domains wordpress wordpress

Sharing CSS stylesheets across different domains


What you suggested is fine. I'm not sure that there is an advantage called "cross-domain loading", but hosting your style sheets in another server is a very common practice. This other server is known as a CDN, or Content Delivery Network. Here's some information about CDNs and their advantages:

http://www.sitepoint.com/7-reasons-to-use-a-cdn/


Also, pro-tip: do some DNS prefetching if you're going to use a separate domain to host your files. It's as easy as:

<link rel="dns-prefetch" href="//myexternalcdn.com" />


try to separate layout structure and templates and call everything from the same domain

<link rel="stylesheet" type="text/css" media="all" href="fileserverdomain/css/structure.css" /><link rel="stylesheet" type="text/css" media="all" href="fileserverdomain/css/firsttamplatename.css" />

OR

<link rel="stylesheet" type="text/css" media="all" href="fileserverdomain/css/structure.css" /><link rel="stylesheet" type="text/css" media="all" href="fileserverdomain/css/secondtamplatename.css" />

Benefit of this solution is that you can adtionaly offer switching templates :D


You can use this filter, to filter out styles with any condition or alternate output href string, example:

add_filter( 'style_loader_src', function($href){if(strpos($href, "name-of-allowed.css") !== false) {return $href;}return false;});