CDN

Jafo

Active member
Will there be any considerations for CDNs? I had to create a product for our sites to utilize origin pull over at Softlayer and even so, found it tricky to hook in everywhere I needed too (i.e. public attachments). Will there be any thought given to this in development?
 
I notice a lot of CDN users don't cache their images (by checking headers), believing a CDN is cached already "somehow". These compinies have a bigger incentive (aka profit) for you requesting images on each visit, so the needed info is hardly shared about setting a proper cache-control header. That one simple trick can literally shave tens of thousands of requests per month of your bill, especially if you think hosting 100 smilies there is a good idea, and they get requested every time someone opens a page x 2000 hits a month. Now we are talking 100'000's of requests.

Just for the record, I use a CDN and all that can be cached is cached, and it's still something I had to look into and make work, rather the CDN being the brilliant thing it could be from the day I joined. Just a lot of sites I see using these services are not taking full advantage of it cost wise.
would like to see if you can share tips on how you do your caching.
 
would like to see if you can share tips on how you do your caching.

By setting all images to a year in the future I had great success.

This option lets you control how long a client accessing objects from your S3 bucket will cache the content and thus lowering the number of access to your S3 storage. In conjunction with Amazon CloudFront, it controls the time an object stays in an edge location until it expires. After the object expires, CloudFront must go back to the origin server the next time that edge location needs to serve that object. By default, all objects automatically expire after 24 hours when no custom Cache-Control header is set.

I use amazon so I have a few ftp like tools I can use, I'm unsure of other providers. You can set the headers with the tools your host uses/lets you use.

HTML:
Cache-Control public, max-age=7776000

Capture3.webp


I was running all my xenforo forum images, two large wordpress sites plus all the uploaded images in wordpress, and about 100 smilies. Each image = 1 request. They add up (the GB's are a separate matter :p)

Capture2.webp

stated caching images for a year, we are not changing anything so that suits us.
Two months later, after increased traffic, I compare the 2 months ago bill above to the one I get now, and I'm caching things.

Capture.webp

Massive reduction in requests. Freakin huge actually. I've saved like 300,000 on the states alone, and our traffic has grown slightly too, so it's definitely a benefit.

You can do it on your server with htaccess too
http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html

I'm using this in the root htaccess file, again it's suited to our sites, but will be good for anyone I guess.

PHP:
Header unset Pragma
FileETag None
Header unset ETag

# 1 YEAR
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "public"
Header set Expires "Mon, 10 Jan 2012 20:00:00 GMT"
Header unset Last-Modified
</FilesMatch>

# 2 HOURS
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>

<FilesMatch "\.(js|css)$">
Header set Cache-Control "public"
Header set Expires "Mon, 10 Jan 2012 20:00:00 GMT"
Header unset Last-Modified
</FilesMatch>
 
Does that .htaccess file also have an effect on my files stored in a S3 bucket served via CloudFront?
I am testing S3 right now and I am very much interested into reducing my cost. Who isn't? ;-)
 
I could certainly see CDN being everyone's friend over the coming years if the price decreases, considering the way the web is slowly decreasing in speed and localization provides far better performance, especially for big boards.

I have to say that kind off boggles the mind though to think of a forum in a CDN setup, pushing and pulling data behind the scenes between locations.
GoGrid resell Edgecast CDN, have a Sydney presence and are pretty affordable. Gives me a good mix of US based server and local speed.
 
I found it was getting avatars from the CDN, and when users updated their avatar it was still showing the old avatar.

I've just set up my cdn by aliasing a sub-domain to the edgecast IP, is there a way to push changed files to the CDN?
 
I found it was getting avatars from the CDN, and when users updated their avatar it was still showing the old avatar.

I've just set up my cdn by aliasing a sub-domain to the edgecast IP, is there a way to push changed files to the CDN?
MaxCDN has a cache purge function, I'm guessing they'll have something similar.
 
MaxCDN has a cache purge function, I'm guessing they'll have something similar.
They do, however I don't want to log in and purge the whole cache each time someone changes an avatar... I guess the issue is because a user avatar

Upon further investigation, I think I've found out why...

In VB, the Avatar URL was: http://www.greenandgoldrugby.com/vb/image.php?u=2&dateline=1310274141

While in XF, the Avatar URL is: http://www.greenandgoldrugby.com/community/data/avatars/l/0/2.jpg?1324114355

Note the version token is now after the .jpg file

There is a setting in GoGrid (my Edgecast reseller) which I had to change to 'Unique Cache' so I think this will now work
Query-String Caching controls how files are to be cached when they contain query strings. Three different modes available, and they are as follows:

"standard-cache": This is the default mode, in which all query strings for a given URL map to the cache file. The file is cached as if there were no query string present: /a.js?v=1 and /a.js?v=2 and /a.js all map to the same cache file. Note however that whenever a cache server must contact an origin server, either on a cache miss or to revalidate an expired cache file, the full query string (if any) from the current end-user request is passed along to the origin server.

"no-cache": In this mode, any URLs containing query strings are not cached and always result in a proxy request to the origin server.

"unique-cache": In this mode, each unique query string maps to a unique cache file; /a.js?v=1 and /a.js?v=2 and /a.js all map to different cache files (even if some of them ultimately have the same content). If you use this mode, we recommend that you also enable query-string logging in the query-string logging page.
*IMPORTANT NOTE* This mode should not be used when the query string contains parameters that will change with every request, such as a session id or a user name, since this would result in a very low cache hit ratio. If token auth is enabled, query-string caching can not be enabled.

standard-cache
no-cache
unique-cache
 
anyone have guide how to setup amazon cloudfront with xenforo?

I had a look at Amazon Cloudfront but didnt think it was ideal to use as (as far as I found) there was no way to purge the cache on the edge servers and you had to wait for the file to expire. That would suck pretty badly in the case of upgrading the forum and you need to push the updated files. Perhaps you can get around this by manually uploading the changed files? Something to look into.

MaxCDN works well as you can purge the cache from their dashboard when you've upgraded and the next refresh of the website it will pull the new file from your server,

To answer your question though, I was going to follow this page to setup a pull zone on Cloudfront
http://anything-digital.com/update/...-the-performance-of-your-joomla-web-site.html - yes that's Joomla but the setting up of the pull zone on cloudfront is the important part. Look for the configure cloudfront section.

On another note, has anyone had any success in setting fully public attachments to be served from the CDN ? Care to share the changes you have to make to get that to work ? I'm guessing it's just a path change somewhere for viewing the attachments in posts ? Or is serving all attachments from a CDN not possible (yet) ?
 
There is a setting in GoGrid (my Edgecast reseller) which I had to change to 'Unique Cache' so I think this will now work
Did you confirm if it works?
I have MaxCDN and I found that new avatar won't take. And I don't want to purge the cache every five minutes so I just comment out the CDN part for avatar on the config file.
Would be nice to see if it works on MaxCDN.
 
Did you confirm if it works?
I have MaxCDN and I found that new avatar won't take. And I don't want to purge the cache every five minutes so I just comment out the CDN part for avatar on the config file.
Would be nice to see if it works on MaxCDN.

You're using a pull zone on MaxCDN ? Ive got avatars uploading and updating perfectly fine on MaxCDN and i'm not purging the cache at all.
 
What are your settings in XF/MaxCDN?
I have a pull zone and I have nginx as my server.

Nothing special with the settings. I'm using pull zone and apache server.

I set up a pull zone in MaxCDN (left all settings as default)
Added a custom domain cdn-data.domain.com in MaxCDN
created a CNAME on my domain
Added the externalDataUrl in config.php
MaxCDN started serving avatars from CDN (confirmed with view image source)
Upload new avatar, starts serving new avatar straight away.

It's not a browser cache issue is it ? What happens when you upload a new avatar ? does it show the new avatar when you upload but not in posts, or it doesnt show the new avatar at all ?
 
Top Bottom