Page 1 of 1

Loading Style Images from another Domain ..?

Posted: Fri Nov 12, 2010 9:28 am
by manutoo
Hello,

I'd like to access Style Images (and other Style stuff) from a cookieless Domain, instead of my main domain.

For example, the user browser receives this kind of URL :

Code: Select all

background-image: url(./styles/prosilver/imageset/forum_unread.gif)
I'd like to replace it this with :

Code: Select all

background-image: url(http://static.mydomain.com/Forum/styles/prosilver/imageset/forum_unread.gif)
I just spent a good bunch of time looking at acp_styles.php , but I didn't find anything meaningful to me.

Anyone would have an idea where I could throw a :

Code: Select all

$FinalHtmlPage = str_replace('./styles', 'http://static.mydomain.com/Forum/styles', $FinalHtmlPage);
..?

Thanks for any help ! :)

Re: Loading Style Images from another Domain ..?

Posted: Fri Nov 12, 2010 10:39 am
by Ather
depends on your style, if its a prosilver based, the CSS Files in the theme folder needs to be edited to load the images

Re: Loading Style Images from another Domain ..?

Posted: Fri Nov 12, 2010 10:58 am
by manutoo
Images in Style config are only names, there's no path, example :

Code: Select all

img_forum_unread = forum_unread.gif*27*27
so I can't change anything there...

Also, I'd like to have the .js & .css files loaded from the other domain as well...

Re: Loading Style Images from another Domain ..?

Posted: Fri Nov 12, 2010 11:16 am
by Ather

Code: Select all

span.corners-top {
	background-image: url("{T_THEME_PATH}/images/corners_left.png");
see the file colors.css

regarding the JS, you'll need to edit the overall_header.html file

Re: Loading Style Images from another Domain ..?

Posted: Fri Nov 12, 2010 12:49 pm
by manutoo
same than above, {T_THEME_PATH} is relative to the phpbb path, so this cannot be edited directly...

Re: Loading Style Images from another Domain ..?

Posted: Fri Nov 12, 2010 1:31 pm
by Ather
yes, you can change that URL to your needs

Re: Loading Style Images from another Domain ..?

Posted: Fri Nov 12, 2010 2:24 pm
by imkingdavid
As in the example posted above, {T_THEME_PATH} consists of the relative path from the phpBB root to the theme folder.

One option is to do a find/replace-all command on {T_THEME_PATH} and use whatever manual URL you wish to use.

Another option is to look in functions.php's page_header() function, find where T_THEME_PATH is assigned, and change it there. This is the recommended way of doing it, as it requires less changes.

Re: Loading Style Images from another Domain ..?

Posted: Fri Nov 12, 2010 2:50 pm
by manutoo
thanks imkingdavid , functions.php's paths are exactly what I needed ; there are a little bunch to change, but it works fine & it's easier to handle in case of future change..! :)

Re: Loading Style Images from another Domain ..?

Posted: Sun Nov 21, 2010 3:33 pm
by manutoo
Ok, actually, I needed a few other paths, so here the other files to check, if anyone else needs the info :
- includes/functions_content.php for 'smilies_path'
- includes/session.php for 'imageset_path'
- style.php for 'imageset_path' & a few others

Hopefully, I'll see a decrease in my incoming B/W in the next hours ! :)

Re: Loading Style Images from another Domain ..?

Posted: Sun Nov 21, 2010 4:22 pm
by Ather
actually, if you are running apache httpd, you can setup a lighttpd on different port and set it to cache your images and other less-changed stuff

Re: Loading Style Images from another Domain ..?

Posted: Mon Nov 22, 2010 3:15 am
by manutoo
I'm not sure what exactly bring lighttpd, but in this case, I just wanted to avoid the sending of cookies for each sub-element request (for more info, see here : http://code.google.com/speed/page-speed ... lessDomain )

It seems my incoming B/W lowered by 10 or 20% so I guess my objective is reached... :)

Re: Loading Style Images from another Domain ..?

Posted: Wed Jul 13, 2011 4:04 am
by GravityDK
This is such a good tip. I've been wanting to offload my theme's static images for ages, too, but had never found the answer.

If you combine it with cloudflare.com, or any content delivery network, you can definitely get a boost to speed.

I'll go try implementing now, too.

Re: Loading Style Images from another Domain ..?

Posted: Wed Jul 13, 2011 4:46 am
by manutoo
Here an example ; the only line I changed in "includes/functions_content.php" was :

Code: Select all

'<img src="' . $root_path . $config['smilies_path'] . '/\2 />',
to :

Code: Select all

'<img src="' . "http://static.MyDomain.com/Forum/" . $config['smilies_path'] . '/\2 />',
ie:

Code: Select all

$root_path
changed to :

Code: Select all

"http://static.MyDomain.com/Forum/"
In "style.php", it's {$phpbb_root_path} instead of $root_path , that needs to be changed...

Re: Loading Style Images from another Domain ..?

Posted: Thu Jul 14, 2011 6:06 am
by GravityDK
I'm using 3.0.7pl1, and the change that made this finally work, on many images, is below.
That said, I still have quite a few images which are not hosted on static, even after changing all the files noted above. Can't work out how to fix them all, yet!

Changed session.php line 2240 from

Code: Select all

			$img_data['src'] = $root_path . 'styles/' . rawurlencode($this->theme['imageset_path']) . '/imageset/' . ($this->img_array[$img]['image_lang'] ? $this->img_array[$img]['image_lang'] .'/' : '') . $this->img_array[$img]['image_filename'];
to

Code: Select all

			$img_data['src'] = "http://static.mydomain.com/forum/" . 'styles/' . rawurlencode($this->theme['imageset_path']) . '/imageset/' . ($this->img_array[$img]['image_lang'] ? $this->img_array[$img]['image_lang'] .'/' : '') . $this->img_array[$img]['image_filename'];