Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Host textpattern images on a subdomain for speed increase
Hi,
I’ve been playing around with Google’s page speed plugin for Firebug on a new site I’m building and following their recommendations to see how high I can get the page speed rating – currently I’ve got to 93/100 but have hit a wall…
One of the Google recommendations is to serve images (and other static content such as css, javascript) from a subdomain to take advantage of parallel downloads and also the fact that you can make the subdomain cookieless.
This is no problem for any images outside of textpattern management, but I can’t seem to find a way to specify a subdomain for the textpattern images folder, as the admin->advanced preferences states that it has to be a relative URL to the textpattern folder. Can this be done at all? I’ve noticed that you can set an absolute server path for files but not it seems for images.
I found this old forum post which brushed on this topic before, but noone thought it a worthwhile pursuit back in 2006. I don’t want to use 301 redirects or anything hacky in the htaccess file either.
I realise this is quite OCD but it would be nice if there was a solution!
Offline
Re: Host textpattern images on a subdomain for speed increase
philwareham wrote:
I realise this is quite OCD but it would be nice if there was a solution!
I’m pretty sure you’re not alone in having that condition round these parts. I’ve been trying to figure the same thing for a while now. Haven’t tried hard, I admit. I figured it might just come to me in a flash.
So far, no flashes.
It would make sense to serve txp files from a static domain too. The bonus would be making version control a whole lot simpler with all those content files out of the way. When he returns from training up in the mountains I’m hoping Maniqui will have the answer to this and other hithero unsolvable mysteries of the universe.
ps. Your site feels pretty zippy already – looks like the page speed homework paid off :-)
Offline
Re: Host textpattern images on a subdomain for speed increase
Note that some web hosts may not allow it, their ‘anti-hot linking’ filters may see it as an attempt to steal bandwidth, even though it is your pictures it is linking to in a sub-domani. You might ask them about it.
As for how, I don’t think it is all that hard.
If your domain is www.joe.net and you make a sub-domain of bill.joe.net with an images folder in bill.joe.net
<,img src=“http://bill.joe.net/images/name_of_file”></a> on a page in www.joe.net
I put the comma in there to show the html markup. I’m still learning the methods used here.
Offline
Re: Host textpattern images on a subdomain for speed increase
The upcoming Textpattern 4.3.0 release will support a new configuration constant ihu
in config.php
for this purpose. Example:
define('ihu', 'http://static.example.com/');
See r3350 for details.
Offline
Re: Host textpattern images on a subdomain for speed increase
Great news. Thanks Wet.
Offline
Re: Host textpattern images on a subdomain for speed increase
Thanks all, I’m using r3380 from SVN anyway so I’ll check out that config and let you know how I get on.
@JimJoe, the original issue was that textpattern (up to 4.2.0 anyway) needs it’s images folder in the same domain as the textpattern install, thanks anyway.
pieman wrote:
ps. Your site feels pretty zippy already – looks like the page speed homework paid off :-)
Thanks, that site (lovethegarden.com) is not the one I’ve been optimising (although I have done some speed work on it previously) but I will move all techniques from my new site back to that one as well eventually. There really is a noticeable speed improvement when following Google’s speed tips which I’m quite surprised/pleased about.
For the record, I don’t think is possible to achieve 100/100 on Google Speed Tools (the Google UK homepage only scores 93 itself).
Offline
Re: Host textpattern images on a subdomain for speed increase
A little promotion for a commercial tool which I use as my swiss army knife to speed up sites. ‘Distribute images’ is one of the many features.
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline
Re: Host textpattern images on a subdomain for speed increase
Using textpattern r3380, my previous place for storing images was www.mysite.com/images/cms/ and I now want my site to serve txp images from static1.mysite.com/images/cms/ so:
1. Added following code to config.php
define('ihu', 'http://static1.mysite.com/')
2. Left the images directory in admin->advanced preferences as “/images/cms”
3. Moved existing images to the subdomain and made the folder chmod 777
Now all existing images are now served from the subdomain as expected which is great, but if I add a new image through textpattern it is not being loaded into the directory in the subdomain. In fact, it’s still wrting new images to the old directory at www.mysite.com/images/cms/
Is this a bug or have I set it up wrong?
Offline
Re: Host textpattern images on a subdomain for speed increase
From your webserver’s file system point of view, the images have to stay in their original directory. Textpattern will always add new images just like it does without the optional ihu
constant in config.php
. Do not move or copy the image files.
The most simple setup is to define static.example.com
as a mirror domain for www.example.com
. Thus, images are served from http://static.example.com/images/cms/
and saved into the webserver’s file system at $WEBROOT/images/cms/
.
Offline
Re: Host textpattern images on a subdomain for speed increase
Oh, I see. Would it not be a better option to allow an absolute path for images in the admin preferences like it is for files? Sorry, but I have no knowledge of how much work that would be to engineer or even if it’s possible – but from an end user perspective that would be the best option.
Offline
Re: Host textpattern images on a subdomain for speed increase
Hi.
off the top of my head a mountain
@philwareham: I don’t think that allowing an absolute path (on webserver’s file system) for uploading images would be a better option (must admit that I’ve thought the same in the past).
It would probably lead to many cases of users uploading images to publicly unreachable locations, that is, to use this preference in the wrong way. It’s not the same as files (which can be relocated by setting an absolute path to somewhere else in the filesystem, as you have noted), as TXP has a built-in mechanism to serve files which are not publicly reachable.
That being said, I think you have other options to approach this:
A) imho, wet’s suggested trick of using a mirror domain seems the easiest & quicker solution, probably easy to set up even on a cheap hosting plan.
B) create a subdomain, and configure its DocumentRoot
to point to /path/to/images/
(where images
is the folder where TXP stores the images). Your images would be located at http://static.mydomain.com/
.
C) similarly, create a subdomain, point it to wherever folder you want, and then, inside that folder, create a symlink to /path/to/images/
(where images
is the folder where TXP stores the images). Your images would be located at http://static.mydomain.com/images/
.
D) similarly, you could try removing the “standard” /images/
folder that comes with TXP and re-create it as a symlink to a folder located inside the DocumentRoot
path for a subdomain. Your images would be located at http://static.mydomain.com/images/
.
Regarding the cookieless subdomain trick, i think it’s only possible if you server static assets from a totally different domain name. That is, you need to use another domain name to be able to serve cookieless stuff. That’s why you will usually see that Facebook or Flicker serve their static stuff not from subdomain, but from totally different domains, like fbcdn.net
or yimg.com
.
Offline
Re: Host textpattern images on a subdomain for speed increase
maniqui wrote:
Regarding the cookieless subdomain trick, i think it’s only possible if you server static assets from a totally different domain name.
Depends.
If you set cookies using a cookie domain of .example.com
(note the leading dot), all subdomains of example.com
would share this cookie. OTOH, if you used example.com
(no leading dot) as the cookie domain, it would only be used on this particular host.
You can try this for yourself in a JavaScript console (replace example.com
with your real domain name):
- Go to
www.example.com
, your “real” website - Enter
document.cookie="globalcookie=global;domain=.example.com"; document.cookie="localcookie=local";
at the JS console prompt. - Enter
document.cookie
to review the set values. The expected result islocalcookie=local; globalcookie=global
. - Go to
static.example.com
, your static subdomain. - Enter
document.cookie
at the JS console prompt to review the set values. The expected result isglobalcookie=global
.
Textpattern itself does not set cookies for the whole domain but only for the particular host which it is run on. Other products on your site like analytics, affiliate tracking et cetera may differ.
Offline