Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing CSS stylesheets across different domains

I'm working on two different WordPress sites that are in many ways similar but are skinned differently.

For example, let's say I'm working on two 'magazine' sites, which share the same CSS layout e.g. grid system, margin's etc., but different CSS decorational properties e.g. gradients, colours, shadows.

What is the best way to get them to share the same base CSS layout, but different decorational CSS?

Initially I thought something like ...

<link rel="stylesheet" type="text/css" media="all" href="LINK-TO-BASE-CSS-ON-PRIMARY-DOMAIN.css" />
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'template_url' ); ?>/style.css" /> <!-- This would be the 'top-up' CSS -->

This doesn't seem particularly clean to me though. I admit though, there is also a very similar question here.

Is this still considered the best way? Are there any disadvantages to linking to another domain? I've read that this may even be an advantage because of cross-domain loading.

like image 537
SparrwHawk Avatar asked Feb 18 '23 05:02

SparrwHawk


2 Answers

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" />
like image 64
Ayman Safadi Avatar answered Feb 28 '23 08:02

Ayman Safadi


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

like image 26
tkeram Avatar answered Feb 28 '23 10:02

tkeram