Loading Style Images from another Domain ..?

Discussion forum for MOD Writers regarding MOD Development.
Locked
manutoo
Registered User
Posts: 19
Joined: Wed Nov 24, 2004 3:33 pm
Location: France
Contact:

Loading Style Images from another Domain ..?

Post by manutoo » Fri Nov 12, 2010 9:28 am

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 ! :)

Ather
Registered User
Posts: 1032
Joined: Fri May 08, 2009 9:42 am
Location: Kingdom of Bahrain
Name: Ather Akber

Re: Loading Style Images from another Domain ..?

Post by Ather » Fri Nov 12, 2010 10:39 am

depends on your style, if its a prosilver based, the CSS Files in the theme folder needs to be edited to load the images
CPL Syed Ather Akbar
Regional Command Southwest
Camp Leatherneck, Afghanistan

My Mods/Snippets

manutoo
Registered User
Posts: 19
Joined: Wed Nov 24, 2004 3:33 pm
Location: France
Contact:

Re: Loading Style Images from another Domain ..?

Post by manutoo » Fri Nov 12, 2010 10:58 am

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...

Ather
Registered User
Posts: 1032
Joined: Fri May 08, 2009 9:42 am
Location: Kingdom of Bahrain
Name: Ather Akber

Re: Loading Style Images from another Domain ..?

Post by Ather » Fri Nov 12, 2010 11:16 am

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
CPL Syed Ather Akbar
Regional Command Southwest
Camp Leatherneck, Afghanistan

My Mods/Snippets

manutoo
Registered User
Posts: 19
Joined: Wed Nov 24, 2004 3:33 pm
Location: France
Contact:

Re: Loading Style Images from another Domain ..?

Post by manutoo » Fri Nov 12, 2010 12:49 pm

same than above, {T_THEME_PATH} is relative to the phpbb path, so this cannot be edited directly...

Ather
Registered User
Posts: 1032
Joined: Fri May 08, 2009 9:42 am
Location: Kingdom of Bahrain
Name: Ather Akber

Re: Loading Style Images from another Domain ..?

Post by Ather » Fri Nov 12, 2010 1:31 pm

yes, you can change that URL to your needs
CPL Syed Ather Akbar
Regional Command Southwest
Camp Leatherneck, Afghanistan

My Mods/Snippets

User avatar
imkingdavid
Former Team Member
Posts: 2667
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: Loading Style Images from another Domain ..?

Post by imkingdavid » Fri Nov 12, 2010 2:24 pm

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.
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

manutoo
Registered User
Posts: 19
Joined: Wed Nov 24, 2004 3:33 pm
Location: France
Contact:

Re: Loading Style Images from another Domain ..?

Post by manutoo » Fri Nov 12, 2010 2:50 pm

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..! :)

manutoo
Registered User
Posts: 19
Joined: Wed Nov 24, 2004 3:33 pm
Location: France
Contact:

Re: Loading Style Images from another Domain ..?

Post by manutoo » Sun Nov 21, 2010 3:33 pm

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 ! :)

Ather
Registered User
Posts: 1032
Joined: Fri May 08, 2009 9:42 am
Location: Kingdom of Bahrain
Name: Ather Akber

Re: Loading Style Images from another Domain ..?

Post by Ather » Sun Nov 21, 2010 4:22 pm

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
CPL Syed Ather Akbar
Regional Command Southwest
Camp Leatherneck, Afghanistan

My Mods/Snippets

manutoo
Registered User
Posts: 19
Joined: Wed Nov 24, 2004 3:33 pm
Location: France
Contact:

Re: Loading Style Images from another Domain ..?

Post by manutoo » Mon Nov 22, 2010 3:15 am

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... :)

User avatar
GravityDK
Registered User
Posts: 38
Joined: Mon Feb 22, 2010 7:11 am
Contact:

Re: Loading Style Images from another Domain ..?

Post by GravityDK » Wed Jul 13, 2011 4:04 am

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.

manutoo
Registered User
Posts: 19
Joined: Wed Nov 24, 2004 3:33 pm
Location: France
Contact:

Re: Loading Style Images from another Domain ..?

Post by manutoo » Wed Jul 13, 2011 4:46 am

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...

User avatar
GravityDK
Registered User
Posts: 38
Joined: Mon Feb 22, 2010 7:11 am
Contact:

Re: Loading Style Images from another Domain ..?

Post by GravityDK » Thu Jul 14, 2011 6:06 am

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'];

Locked

Return to “[3.0.x] MOD Writers Discussion”