Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not Solved [General] query strings on avatars
#1
Not Solved
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?
Reply
#2
Not Solved
If you give an link to the site it would be awesome.
Reply
#3
Not Solved
http://damnfineshave.com
Reply
#4
Not Solved
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
[Image: axolis.png]

Project, Portfolio and Product management for freelancers.
Reply
#5
Not Solved
(10-05-2015, 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.
Reply
#6
Not Solved
(10-05-2015, 05:57 AM)andrewjs18 Wrote:
(10-05-2015, 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>
[Image: axolis.png]

Project, Portfolio and Product management for freelancers.
Reply
#7
Not Solved
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
Reply
#8
Not Solved
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.
[Image: banner.png]
Reply
#9
Not Solved
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.
[Image: axolis.png]

Project, Portfolio and Product management for freelancers.
Reply
#10
Not Solved
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/
Random Fish and Sims Maniac
MY PLUGINS
Help MyBBSupport help you - remember to mark your threads as solved


Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)