Hi,
We’re trying to improve our site’s performance and one of the recommendations from YSlow and Google’s page speed is to use a cdn to host our static content. Does anyone know of a way that I can get this working automatically in modx? Ideally I would duplicate the images and scripts folder on a cdn so that editors can still select them in the modx manager, but the urls would be replaced with the cdn folders when the page is published.
Does this sound like something that could be done or is there a simpler way of doing it that I’m missing?
Cheers!
Chris
Thanks for the tip - I’ll check them out. What I’m really after is some advice on how to configure modx to use the cdn, without having to hard code the links to images. Any recommendations?
-
MODX Staff
- 12,272 Posts
You just use it as normal. You’d need to probably create a plugin or use a chunk (or custom system setting like we do in Revo):
{{cdn_url}} for Evo or [[+cdn_url]] for Revo
You’d need to put that in front of each image path or resource you want mapped to the CDN for delivery. Upon first request to the CDN, it will bounce back to your site and grab the resource, and serve it from there on out. So, if your site is example.com and your mirror bucket at SimpleCDN were located at foobahbar.simplecdn.com/example_cdn/ and you have your CDN resources on your site stored in assets/, assets/images/, assets/js and assets/flash/ you’d simply point the CDN bucket to www.example.com/. It takes a second to figure out how to do it but it’s awesome when it works (and we’ll likely switch over to this soon ourselves here at MODx.
You can also map a CNAME (like cdn.example.com) to your mirror buckets at SimpleCDN. The only drawback with mirror buckets on SimpleCDN currently compared to standard file-upload buckets is that mirror buckets do not support Flash/H.264 streaming yet according to their site. They do for tradition upload buckets.
A plugin could dynamically do the same thing before rendering or saving the page if you so desired, but would take a bit more effort. You could do the same thing with Javascript too I suppose.
Ryan Thrash, MODX Co-Founder
Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me