MyBB Community Forums

Full Version: query strings on avatars
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
I display avatars on my forum index and forum display so it'd be ideal if they got cached from the cdn, but they're not because of the query strings.

is there a way to optimize this?
If you give an link to the site it would be awesome.
Since you are using cloudflare you can tweak the caching level to serve a cached version even if there is a query string in the url. The timestamp only changes when the avatar is updated.

This cloudflare article will help:
https://support.cloudflare.com/hc/en-us/...Page-Rules-

Quote:Ignore query string
Caches static content that has a query string and treats it as one file
(2015-10-05, 05:43 AM)SentoWeb Wrote: [ -> ]Since you are using cloudflare you can tweak the caching level to serve a cached version even if there is a query string in the url. The timestamp only changes when the avatar is updated.

This cloudflare article will help:
https://support.cloudflare.com/hc/en-us/...Page-Rules-

Quote:Ignore query string
Caches static content that has a query string and treats it as one file

I'm using incapsula, not cloudflare.
(2015-10-05, 05:57 AM)andrewjs18 Wrote: [ -> ]
(2015-10-05, 05:43 AM)SentoWeb Wrote: [ -> ]Since you are using cloudflare you can tweak the caching level to serve a cached version even if there is a query string in the url. The timestamp only changes when the avatar is updated.

This cloudflare article will help:
https://support.cloudflare.com/hc/en-us/...Page-Rules-

Quote:Ignore query string
Caches static content that has a query string and treats it as one file

I'm using incapsula, not cloudflare.

Sorry, only just realized that you are only using cloudflare for some external JS files. I haven't used incapsula so I am not sure if they make it possible to use more aggressive caching while keeping html files intact.

Have you enabled a CDN in the admin admin panel? (Server optimization options) You can also put a .htaccess file in the uploads/avatars directory telling Incapsula to cache the resource for 1hr, incapsula should then use the same cache header telling all requests that the resource won't change for 1hr. You shouldn't really cache avatars for more than an hour.

The htaccess should contain this:

uploads/avatars/.htaccess
<IfModule mod_expires.c>
  ExpiresActive on
 
  ExpiresDefault "access plus 1 hour"

  <IfModule mod_headers.c>
    Header append Cache-Control "public"
  </IfModule>
   
</IfModule>
Hi,

To remove the query string, you'll have to modify the core a little. The edits are in usercp.php and in admin/modules/user/users.php

In usercp.php, find line 2102: https://github.com/mybb/mybb/blob/de0124....php#L2114

			$updated_avatar = array(
				"avatar" => $avatar['avatar'].'?dateline='.TIME_NOW,
				"avatardimensions" => $avatar_dimensions,
				"avatartype" => "upload"
			);
			$db->update_query("users", $updated_avatar, "uid='".$mybb->user['uid']."'");

Change this to:

			$updated_avatar = array(
				"avatar" => $avatar['avatar'],
				"avatardimensions" => $avatar_dimensions,
				"avatartype" => "upload"
			);
			$db->update_query("users", $updated_avatar, "uid='".$mybb->user['uid']."'");

In admin/modules/users/users.php, find line 621: https://github.com/mybb/mybb/blob/b2cbaa...s.php#L621

					$extra_user_updates = array(
						"avatar" => $avatar['avatar'].'?dateline='.TIME_NOW,
						"avatardimensions" => $avatar_dimensions,
						"avatartype" => "upload"
					);

Change this to:

					$extra_user_updates = array(
						"avatar" => $avatar['avatar'],
						"avatardimensions" => $avatar_dimensions,
						"avatartype" => "upload"
					);

Unfortunately any avatars already uploaded will still have the query strings in the database. It should be possible to fix this with an SQL query, but I'm not at home right now and don't have access to a MyBB database to test on till later. I'll update this post when I get home.

Thanks,
Euan
The downside of removing the query string is that avatars will be cached which means that changing the avatar appears to have no effect until the browser cache is cleared.
I was expecting the timestamp to be the time when the avatar was last updated. Since this turned out to be false core changes is the best option unfortunately.
having the avatars show is really popular though bad for site statistics with these page testing tools. The issue is the ? in the query string isnt it? is there another way of writing that so that the advantage of the dateline is kept without the query string? The js files have the same effect with the query string.

http://www.stevesouders.com/blog/2008/08...erystring/
Pages: 1 2 3 4 5