Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Seperate sub-domain for static content

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2173 Views
  • DJMatus23
    Community Member
    11 Posts

    Seperate sub-domain for static content Link to this post

    Hi all,

    Have been using Google's Page Speed thingy to see what I can do to speed up my page loads. One of the suggestions is to move content to different subdomains, so for example, all css files would come from css.example.com, all images would come from img.example.com, etc. This is all to do with the way browsers queue up all the content they want to download...the more domains, the more the browser will try to download concurrently. It's also got something to do with having cookies on the domain, but that's not really important.

    I was thinking of doing this via http rewrites, or hacking silverstripe, but I'm wondering if this is already supported? Also, before you tell me not to do this, as it makes no real difference, there are other reasons to do stuff to make Google like your website

    Ronan 2.0

  • netnoise
    Community Member
    10 Posts

    Re: Seperate sub-domain for static content Link to this post

    You neither need to hack Silverstripe nor to use rewrites. Simply create a virtual host in your webserver pointing to your theme directory. Turn on gzip compression for this vhost and tweak caching headers.

    Don't create a subdomain for each css, js, images folder as this would slow down things on a medium site due to the extra DNS lookups. Clearly stated in Google's Page Speed docs.

  • DsX
    Community Member
    178 Posts

    Re: Seperate sub-domain for static content Link to this post

    I am using Plesk for my server management.
    Would creating a subdomain for the 'themes' directory do the same?
    and once the themes.mysite.com domain is setup, how do we get silverstripe to use this domain when using $ThemeDir?

  • Hamish
    Community Member
    712 Posts

    Re: Seperate sub-domain for static content Link to this post

    This shouldn't be that hard, but might require a small hack to the core.

    Set up a virtual host pointing to the theme directory. Then set the constant THEMES_DIR to the fully qualified path (eg, static.example.com). This will cause Sapphire to error, as it attempts to redefine THEMES_DIR in core.php - so alter the line with:

    define('THEMES_DIR', 'themes');


    if(!defined('THEMES_DIR')) define('THEMES_DIR', 'themes');

    Be interested to hear how you go.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.