This add-on is operated by CDN Sumo
The easiest way to improve app performance
Table of Contents
What is a CDN?
A CDN is used to distribute content around the world so that it is closer to your customers, and closer content means faster content. By using a CDN to serve static assets of your website, you can speed up page load time and reduce load on your app server at the same time. When you provision CDN Sumo a CDN will be created just for you, all you have to do is configure your app to use it.
How content is propagated to the CDN
The CDN does no initial content propagation, nor do you need to push content to your CDN. On a per request, per geographical location basis, content is fetched by the CDN from your app and subsequently cached for as long as you set the TTL (time to live) for. In this respect, the CDN can be considered to “proxy” requests.
What happens when content is fetched by the CDN
- The request is forwarded to the nearest CDN location.
- If the file is not found in that CDN node’s cache, the request is forwarded to the app.
- The app sends the requested files back to the CDN location.
- The CDN forwards these files to the end user.
- The file is cached on the CDN.
Note that if the file is not yet in the CDN cache, the request is “proxied” through the CDN.
A note on 404’s
As long as the content is available from the app, the CDN will never return a 404 (due to the “proxy” nature of the CDN).
A note on expired assets
It is possible for the CDN to serve an expired asset if the host server is unavailable. This can be configured by setting the cache expiration time (TTL). (see below)
A note on CORS
CDN Sumo does support setting custom CORS headers. If you encounter trouble loading assets (such as fonts, especially in FireFox) that are hosted elsewhere than where CDN Sumo is installed, you should first ensure that that host is correctly setting the
Access-Control-Allow-Origin header. For more information check out this Stack Overflow thread.
Where are our CDNs?
CDN Sumo uses Fastly as our CDN provider. This map shows all global POPs.
Provisioning CDN Sumo
CDN Sumo can be attached to a Heroku application via the CLI:
A list of all plans available can be found here.
$ heroku addons:add cdn_sumo -----> Adding cdn_sumo to sharp-mountain-4005... done, v18 (free)
Once CDN Sumo has been added a
CDN_SUMO_URL setting will be available in the app configuration and will contain the URL used to host your assets. This can be confirmed using the
heroku config:get command.
$ heroku config:get CDN_SUMO_URL your-app-name.fastly.net
CDN_SUMO_URL will be available immediately, however sometimes it may take up to a minute to finish up CDN configuration.
How does a CDN work with my app?
The CDN that you receive from CDN Sumo dynamically grabs and caches assets from your domain, so you don’t need to sync. You can set up your app so that it instructs browsers to deliver content from your
CDN_SUMO_URL instead of your own app server. This especially easy if you are using a framework like the Rails asset pipeline to deliver assets.
CDN Sumo with the Rails Asset Pipeline
To use your CDN with the asset pipeline (Rails 3.1+), you will need to tell Rails the domain where you want your assets to be delivered from instead of your server. Open up
config/environments/production.rb and add the following code (it may be commented out by default):
config.action_controller.asset_host = ENV['CDN_SUMO_URL']
This tells your Rails app to serve assets from the CDN Sumo domain in production.
You may also need to set
config.serve_static_assets = true if you have content in /public that your web server does not serve.
You should also set these options in your environments config:
config.static_cache_control = "public, max-age=2592000" config.assets.digest = true
config.static_cache_control = "public, max-age=2592000" tells Rails that all static assets are considered public and sets the TTL (how long to cache) for 2,592,000 seconds (30 days). While this may seem like a very long time, you don’t have to worry about expiring assets, that’s what the next line is for.
config.assets.digest = true will tell Rails to take an MD5 sum of all your assets and add it to the filename. This way the asset is “fingerprinted” and if you ever change the file, the filename will change since it has a different “fingerprint”.
For example if you have a file called
sumo.jpg and it’s MD5 hash is
908e25f4bf641868d8683022a5b62f54 then the filename will be
If you modify the asset in any way, the hash will change and so will the filename. By using digests you don’t have to worry about invalidating your own assets, the filename take care of everything for you. For more information on this behavior check the Rails Asset Pipeline Fingerprinting guide.
With CDN Sumo your plan is calculated based on requests and data transfer, having unused content on the CDN will not affect you. If you are doing rolling deploys, this behavior is actually beneficial since older assets will still be available after the new server is brought online.
CDN Sumo now supports invalidating (purging) individual files or the entire cache, but using digests or “fingerprinting” is highly recommended as it is much easier to work with. If you have any problems, check the “Verifying your CDN Works” section below.
CDN Sumo with other Frameworks
If you’re using another framework let us know and we will add docs: firstname.lastname@example.org
Verifying your CDN Works
If you are forcing redirects of http to https, you need to set up CDN Sumo to pull content from your origin over SSL. This can by done by setting the port to 443 in the CDN Sumo dashboard.
Once you’ve provisioned CDN Sumo you will receive a confirmation email that includes your CDN URL for your records. Make sure you’ve deployed the code changes listed above that configure your app for use with CDN Sumo. You can verify that assets are coming from the CDN by visiting your application in the browser and then viewing source. Any assets that would be served by the asset pipeline such as
application.css should be coming from the domain that matches your
CDN_SUMO_URL such as:
If the domain does not match the current value of your
CDN_SUMO_URL you need to double check that your app is configured correctly and that the most recent code changes have been deployed.
If you see the right URL but the wrong content, try viewing that content directly by copying and pasting your asset URL into your browser bar. If you are getting an error, verify that your app is serving the right content. You can do this by taking the path, in this example
, and trying to view that file from your own domain instead of through the CDN. So if your app was hosted on
twilight-firefly-2974 you could visit:
If the asset does not render, there is nothing wrong with the CDN, but rather a problem exists in your app. Check the deploy output to make sure there were no errors, check your heroku logs:
$ heroku logs --tail
Another useful tool is to verify the files exist on the dyno as you expect. You can do this by running:
$ heroku run bash
ls to verify the presence of files,
cat to verify the contents, and
cd to navigate directories. If you’re confident that your application is serving the correct file but you’re not seeing the right thing coming through the CDN please contact support.
Migrating between plans
Application owners should carefully manage the migration timing to ensure proper application function during the migration process.
heroku addons:upgrade command to migrate to a new plan.
$ heroku addons:upgrade cdn_sumo:newplan -----> Upgrading cdn_sumo:newplan to sharp-mountain-4005... done, v18 ($49/mo) Your plan has been updated to: cdn_sumo:newplan
Removing the CDN Sumo Add-on
CDN Sumo can be removed via the CLI.
This will destroy all associated data and cannot be undone!
$ heroku addons:remove cdn_sumo -----> Removing cdn_sumo from sharp-mountain-4005... done, v20 (free)
If after installing CDN Sumo you are seeing a redirect loop and you are forcing redirects to https from http, you will need to configure CDN Sumo to pull content from your origin over SSL. This can be done by setting the port to 443 in the CDN Sumo dashboard.
All CDN Sumo support and runtime issues should be submitted via one of the Heroku Support channels.
Catch us on twitter @CDNsumo
Feel free to send any and all comments to email@example.com