Welcome to WebmasterWorld Guest from 54.159.30.26

Forum Moderators: phranque

using a sub-domain as a cdn

     
5:46 pm on Jan 3, 2018 (gmt 0)

Junior Member

joined:Apr 21, 2016
posts: 57
votes: 7


I searched the site but could not find an answer to my question.

I am trying to move my site assets (css, images,js) to a sub-domain to improve page load speed.
the site is small and local therefore unnecessary to use a CDN.

I set up a sub-domain static.example.com with folders css, img and js.

I changed my link from
<link rel="stylesheet" href="<?php get_theme_url(); ?>/css/styles.css">

to
<link rel="stylesheet" href="http://static.example.com/css/styles.css">

I also added a cname pointing from static to www.example.com

but the pages are not seeing the css.

clicking on the link from the source code shows the CSS file, so what am I missing?

thanks
6:40 pm on Jan 3, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 19, 2002
posts:3356
votes: 39


i'd suggest converting your site to SSL and serving your pages with http/2 if your host is up to date enough, that way you needn't bother with subdomains for what you want to do, as http/2 makes that concept obselete.

... i know this doesn't answer your question but it just a suggestion that you may not have considered.

>>clicking on the link from the source code shows the CSS file, so what am I missing?
refresh the page, clear your cache, rinse and repeat, it should work.
6:55 pm on Jan 3, 2018 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14442
votes: 576


When you use LiveHeaders-or-equivalent* what requests & responses are you seeing? (Remember to re-enable .css, .png and so on if, like me, you normally are only interested in page requests.) Is the request going to the wrong place, is it receiving the wrong content, or is it not being sent at all?


* I recently went back to the previous version of Firefox because the new one doesn't support LiveHeaders, and the recommended alternative only shows request headers, which is useless to me.
8:41 pm on Jan 3, 2018 (gmt 0)

Junior Member

joined:Apr 21, 2016
posts: 57
votes: 7


Thank you for your replies and Happy New Year to you.

@topr8,
my site is converted to ssl although the sub-domain is not. I'm not sure that would make a difference in this case.
I had not thought of http/2 and have since contacted my host. The do not support it.

cleared cache, refreshed, no go.

@lucy
I just checked with chrome dev tools and it's showing styles.css (blocked:mixed-content)

Okay, just looked a bit deeper

Mixed Content: The page at 'https://www.example.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://static.example.com/css/styles.css'. This request has been blocked; the content must be served over HTTPS.

so it appears the sub-domain must also be https. I wonder if sub-domains can piggyback off the main domain ssl?
8:53 pm on Jan 3, 2018 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:3566
votes: 197


You don't need a protocol in most cases, you should be able to get it without the http: or https: as in
<link rel="stylesheet" href="/static.example.com/css/styles.css">

or even
<link rel="stylesheet" href="/css/styles.css">
depending on the location of the resource relative to the link.
9:21 pm on Jan 3, 2018 (gmt 0)

Junior Member

joined:Apr 21, 2016
posts: 57
votes: 7


Thanks not2easy, I tried several variations of that returning 404's.

No, the problem lays with the sub-domain being insecure. I'm checking with Comodo to see if I can get the licence changed from www.example.com to *.example.com.

Not holding out much hope and wish I'd realized sooner.
10:12 pm on Jan 3, 2018 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14442
votes: 576


You don't need a protocol in most cases
This is the not-most case ;) because his supporting files are being served from a different subdomain.

I'm pretty sure you can generally get a comprehensive certificate that covers subdomains. But if you've only got the one subdomain, it might be cheaper to get separate certificates. Is a free cert an option? I think you said at the outset that you've got a pretty busy site. (Edit: Oops, no, I'm thinking of someone else's thread.)

There may have been an earlier thread explaining the backstory. Why does your static content have to live on a separate subdomain in the first place? Seems like just one more complication.
10:29 pm on Jan 3, 2018 (gmt 0)

Junior Member

joined:Apr 21, 2016
posts: 57
votes: 7


apparently you can get a comprehensive certificate - wild card. If I had registered the domain as *.example.com, it would have covered all subdomains but because I registered it to www.example.com, it doesn't. I'm checking to see if I can get it changed.

the cert for this site was $65 +/- so no I'm not buying another. Free cert? ha! another reason to change my host.

The reason I'm trying to get static content moved is for page load speed.
11:22 pm on Jan 3, 2018 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14442
votes: 576


Does the subdomain live on a different, speedier server? If not, I can't figure out why page load time would be affected at all. In fact on initial visits there might be a teeny additional lag as the visitor (that is, the human visitor's browser) has to perform an additional lookup.
11:51 pm on Jan 3, 2018 (gmt 0)

Junior Member

joined:Apr 21, 2016
posts: 57
votes: 7


Using a sub-domain is essentially the same as using a CDN ergo concurrent downloads or am I missing something?
9:42 am on Jan 4, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 19, 2002
posts:3356
votes: 39


you are not missing something, the idea is that each sub-domain/domain can send 2 concurrent downloads on an http/1.1 connection. thus it would be quicker. for optimum, you'd split the images between each connection, eg. if you have 10 images, 5 from the domain and 5 from the sub

the cost is for the client to make an extra dns lookup for the subdomain.

on a modern fast connection (assuming you don't have a ridiculous amount of images) i don't think it will make much difference, however not everyone has a modern fast connection, so it can be an improvement for them.