PDA

View Full Version : MULTIPLE cookieless domains (speed improvement)


LuisManson
07-09-2010, 10:00 PM
Since vbulletin uses a LOT of images plus CSS and JS i decided to separate all of them into cookie less domains

First of all on admincp set cookies only for your forum MAIN domain (ie www.mysite.com) not .mysite.com

DNS:
First of all i created some subdomains
static.mysite.com
static2.mysite.com
staticcss.mysite.com
staticjs.mysite.com

all of them pointing to the same server

Web server:
i created a new vhost:

<VirtualHost *:80>
ServerAdmin webmaster@mysite.com"
DocumentRoot "/usr/local/www/estaticos_mysite_com"
ServerName static.mysite.com
ServerAlias static2.mysite.com staticcss.mysite.com staticjs.mysite.com
ErrorLog "/var/log/www/mysite-error.log"
CustomLog "/var/log/www/mysite-access.log" combined

Alias /images /usr/local/www/web_mysite_com/images
Alias /clientscript /usr/local/www/web_mysite_com/clientscript
</VirtualHost>



Filesystem:
My vb site is in: /usr/local/www/web_mysite_com
and the static content is in: /usr/local/www/estaticos_mysite_com
inside this new vhost directory i also made two aliases (because of my permissions)

clientscript -> ../web_mysite_com/clientscript
images -> ../web_mysite_com/images

* given my permission direct access to this shite would give you a forbidden, maybe you could create an empty index file

htaccess:
i have a redirect for my domain so now i had to make a few changes to:

RewriteCond %{HTTP_HOST} !^www\.mysite\.com
RewriteCond %{HTTP_HOST} !^static\.mysite\.com
RewriteCond %{HTTP_HOST} !^static2\.mysite\.com
RewriteCond %{HTTP_HOST} !^staticcss\.mysite\.com
RewriteCond %{HTTP_HOST} !^staticjs\.mysite\.com
RewriteRule (.*) http://www.mysite.com/$1 [L,R=301]


plugin:
go to your admincp and create a new plugin in global_complete hook

$oz_process = str_replace('"http://www.mysite.com/clientscript/vbulletin_css/', '"http://staticcss.mysite.com/clientscript/vbulletin_css/', $output);
$oz_process = str_replace('"clientscript/vbulletin_css/', '"http://staticcss.mysite.com/clientscript/vbulletin_css/', $oz_process);

$oz_process = str_replace('"http://www.mysite.com/clientscript/', '"http://staticjs.mysite.com/clientscript/', $oz_process);
$oz_process = str_replace('"clientscript/', '"http://staticjs.mysite.com/clientscript/', $oz_process);

$output = $oz_process;


*original code from here: https://vborg.vbsupport.ru/showpost.php?p=1910781&postcount=13

images:
Go yo "templates and styles"
choose your style and then in Style Vars filter by imgdir
replace those PATHs with new-hostname/ + original path
IE: images/buttons -> http://static2.mysite.com/images/buttons


NOTE: because a bug in vb code here you can make a real mess, check this report first:
http://tracker.vbulletin.com/browse/VBIV-7479
* Long story short:
a solution that worked for me was from David Grove:

The "fixes" described in the above comments are incorrect. To patch this issue, until v4.0.5 comes out, please edit line 489 of /admincp/stylevar.php, and change TYPE_ARRAY_ARRAY to TYPE_ARRAY.

So lines 485 through 491 should be changed from this:


if ($_POST['do'] == 'savestylevar')
{
$vbulletin->input->clean_array_gpc('p', array(
'stylevar' => TYPE_ARRAY_ARRAY,
'original' => TYPE_ARRAY_ARRAY,
));

To this:

if ($_POST['do'] == 'savestylevar')
{
$vbulletin->input->clean_array_gpc('p', array(
'stylevar' => TYPE_ARRAY,
'original' => TYPE_ARRAY_ARRAY,
));


This is of course, not the complete fix, but it will allow editing stylevars to work until v4.0.5 is released.


and you are done, now your site should be a bit faster

lazydesis
07-15-2010, 12:12 PM
Thanks .. very nice article

does this work for vb3.8? or is it only for vb4?

klaus
07-16-2010, 12:18 AM
If your htaccess goal is to simply force a www you can simplify it to:

RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule (.*) http://www.mysite.com/$1 [L,R=301]

It will now allow anyhost.mysite.com but when its just mysite.com without a subdomain or host it 301's to tripleW.

2lines vs. 6 lines

Sayid
07-16-2010, 04:45 PM
Useful article and it will improve page rank when I use firebug add-on in FF
Thanks and subscribed to this.

tech4c
07-17-2010, 04:55 AM
Demo if you can !

Regards,

LuisManson
07-21-2010, 10:39 AM
thanks all,
Sayid, how could this improve pagerank?
klaus: you are right, im not sure why i did it this way
lazyindian: it should work :)

Shabcool
07-23-2010, 12:47 AM
thanks

as7apcool
09-25-2010, 05:36 AM
thanks 4 useful topic

sivaganeshk
06-15-2011, 04:43 PM
should I paste this code ? where ? or is this commands?

TheLastSuperman
06-18-2011, 05:41 PM
should I paste this code ? where ? or is this commands?

Which code are you referring to? Basically the codes listed above need to be added to files, you edit, add the code then save and check to ensure the changes are present and you setup everything properly.

Post Reader
08-02-2011, 09:31 AM
i am wondering if i can know about the vhost creation