Faster Page Loads with Subdomains for Images & Uploads

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
JeremyBASS

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by JeremyBASS »

The rewrite is more simple then to right it all to the root... all it does is say if a .jpg just remove the www and replace with what have you...


so

http://www.uisge-beatha.eu/uploads/images/MD2020.jpg
would be
http://image.uisge-beatha.eu/uploads/images/MD2020.jpg

Now I have no idea on your set up... but with the .htaccess route all you should do is in the dns create the alias to point to the root.. match you www record, do all the normal alias step you do just point it all to the root.  And that is it... if you tired any of the other routes below then this will not work...

HTH - Cheers Jeremy
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: Symlink works best!

Post by Gregor »

kendo451 wrote:
I did find that image manager generates links with an extra http://domain.com on the front, so until that is fixed you might NOT want to change the path for images in config.php.
Got it working, after a long hassle.

.htaccess

Code: Select all

Order deny,allow
RewriteEngine  on
RewriteCond %{REQUEST_URI} \.(ico|gif|jpg|jpeg|png|flv|pdf|mp3|wav|js|css|kml|xml)$
RewriteCond %{HTTP_HOST} ^www\.image\. [NC]
RewriteRule .* http://www.uisge-beatha.eu/uploads/images%{REQUEST_URI} [R=301,L]
Changes made to config.php

Code: Select all

#Default path and URL for uploaded images in the image manager
#$config['image_uploads_path'] = '/home/efacti/public_html/uisge-beatha.eu/uploads/images';
#$config['image_uploads_url'] = $config['root_url'] . '/uploads/images'; 
$config['image_uploads_path'] = '/home/efacti/public_html/image';
$config['image_uploads_url'] = 'http://www.image.uisge-beatha.eu'; 
When editing pages or using the Image adding tool, I see the subdomain. The image maganager module still refers to the original folder.

Gregor
Last edited by Gregor on Wed Dec 30, 2009 9:01 am, edited 1 time in total.
kendo451

Jeremy, does your solution actually work in the browser?

Post by kendo451 »

Hi Jeremy,

Your Apache Mod-Rewrite solution is definitely the simplest way to get the images to come from a subdomain.

The question is, does it work in the browser?  Obviously you can see it in the browser, but that isn't what I mean.

The reason we do this trick is that when the browser parses an HTML page, it will link to up to four domains to pull images, scripts, and css files, but pulls them sequentially from any one domain.

So by linking to four domains to get the external page elements, you can get four simultaneous connections and make the page load 4 x faster.

Your solution takes links to the same domain and re-writes the url to the subdomain.  But I suspect that at this point the browser has already made its list, and the fact that a url gets re-written isn't going to cause it to jump to the next file on the list.

Have you tested this to see if it actually generates the same performance improvement as using a real subdomain link?

Thanks,
Ken
JeremyBASS

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by JeremyBASS »

here you be the judge...  ;)

http://www.digitalbarn.tv/

and a net shot of one of my test sites is attached.. and yes I do see a gain.. but this is only one of many tricks you could be doing... as you see I have the css and images inline.. now this was the quick test, I also have the components pointed to the subdomain to help avoid any delays which null out the gain.





So if you look at the net there is no redirects...  because from the start I planned for the subdomains..

I'd have to ask to show other sites but overall it's just one of many things to make it snappy...

Best suggestion is to test for yourself.. see if the server your on will some the gain...

Hope this helps..
Cheers


note I have 8 there inline...
Attachments
PREonload.jpg
JeremyBASS

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by JeremyBASS »

Here is another one.. both of these are not as uptodate with the practices I do now but as you can see it's loaded right, also, thou Google is throwing a cookie on it do to the way I set that up there is no other cookie on there... so it did its job of

0-rewrite time (because I'm pointing to the right subdomain)
0-cookie bits from CMSMS
18- inline loads till the js which I'm sure you know that css files hold up imgs which is not happening here, and there is no way to parallel js scripts and is why you should be puting all js at the bottom of you html...

hope that helps...
cheers
Attachments
PREonload-2.jpg
kendo451

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by kendo451 »

Ok, now I realize that my criticism was invalid.  You are using the www.subdomain.domain.com in the links on the actual html page, so the browser still sees each subdomain as a unique domain.

Ken
JeremyBASS

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by JeremyBASS »

Well it's subdomain.domain.tdl but yes pointing right ate the location save the redirect from occurring.. Since most of my module account for this it's not an issue there... and other mods I have canned the parts that need to deal with this.  Mostly just a simple |replace type stuff...

Criticism makes the code strong like bull...  :D

Cheers
Jeremy
kendo451

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by kendo451 »

Ok, Jeremy, now you're confusing me. 

I thought you were recommending the .htaccess - only method as the best.  But now you're saying you actually are pointing the subdomains at the directories using symlinks so they don't have to be redirected by .htaccess ?
JeremyBASS

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by JeremyBASS »

kendo451 wrote: Ok, Jeremy, now you're confusing me. 

I thought you were recommending the .htaccess - only method as the best.  But now you're saying you actually are pointing the subdomains at the directories using symlinks so they don't have to be redirected by .htaccess ?
No.. the elements.. I point those :D  ie:

yeah I see how that could have been read that way .. I use .htaccess and point all dns alias' to the root.  That is what I do :D


Sorry If I was unclear, slip of wording... -J
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by Gregor »

Jeremy, do I understand you correct that as soon as you have a site running for a while, there is no other way than moving all image/pictures to the subdomains (as shown in my previous post) and correcting all (!) links inside the cms to the subdomain?

Gregor
JeremyBASS

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by JeremyBASS »

Gregor wrote: Jeremy, do I understand you correct that as soon as you have a site running for a while, there is no other way than moving all image/pictures to the subdomains (as shown in my previous post) and correcting all (!) links inside the cms to the subdomain?

Gregor
Ok I hope I understood you question right :D
In theory for the 0 lose of potential performance on both the server and the client during rendering of the dom, yes you would want to start off with the right location of the component.  Why put www when it’s media… this can be handled with out really any time spent. 

What I did was look at my gain verse lose… On most servers this is what I see
Gains:-0 cookie bits,
-parallel downloads,   
-Server does no rewrite or redirect
-reduced response and receiving times… I usually see 25-100ms savings per componet


Lose:-You must be strict on practice so your clients editing don’t complain
-Server processes for |replaces where a mod has not provided the subdomain override.

This is what I do… but to be honest I am always trying something to see if I can find a better way.. You don’t have to do this.. But when it’s put in your style of construction it adds little in the way of time so for me there is no reason not to.
My2Cents here … hope this helps show what I’m thinking and doing  :)
Cheers
Jeremy
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by Gregor »

Thanks Jeremy. This supports the thoughts I had on this one.

An improvement I can make, is to put the js-files and de css-files onto a subdomain. Allthough I have to check/see/measure if putting the cs-files on a subdomain would be a faster load than useing the {stylesheet} tag.

Any suggestions for improvement of the load time, are more than welcome  :)

Gregor
kendo451

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by kendo451 »

Gregor, you could keep the stylesheet tag, and just change a rewrite rule so that it triggers if stylesheet.php is contained in the url, and the url begins with css.
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by Gregor »

Thanks for your quick reply. I will see if I understand the way the css-files are loaded so I can change it as you suggest. What is crossing my mind, is that they are loaded into the database, if I'm correct on my setup. All stylesheets are placed in the folder 'stylesheet'.

Code: Select all

{static_stylesheet}
<!-- This is how all the stylesheets attached to this template are linked to -->

{cms_selflink dir="start" rellink=1}
{cms_selflink dir="prev" rellink=1}
{cms_selflink dir="next" rellink=1}
<!-- Relational links for interconnections between pages, good for accessibility and Search Engine Optmization -->
Gregor
Last edited by Gregor on Thu Feb 11, 2010 6:51 am, edited 1 time in total.
kendo451

Re: Faster Page Loads with Subdomains for Images & Uploads

Post by kendo451 »

Did some more work on this last night.

If you want the stylesheets to use your congifuration, then you need to edit the function.stylesheets.php plugin in the plugins directory.

I am making a copy of the plugin, and renaming it so that it won't be overwritten when I upgrade CMSMS.

So the new one is function.css_stylesheets.php and I change the function name to _cms_stylesheets inside.

I haven't finished this yet, but I'll post it here if/when I get it working.
Post Reply

Return to “Tips and Tricks”