CSS/JS Library CDN


This resource allows you to load common Javascript and CSS libraries from a single source. It exists because we were experiencing significant downtime with the common public CDN providers. While none of them were experiencing huge downtime, it never overlapped with our own and therefore caused problems.

The idea here is to maximize the convenience of the public CDN providers, so this resource is essentially a caching proxy of those providers.

Performance Note: This CDN is almost guaranteed to have worse uptime than the source CDNs. It also is pretty much guaranteed that visitor's won't have the files cached on first visit. It only makes sense to use it if you are also using one of the other assets on this server.


Documentation and Examples

To use, rewrite the URL of the CDN provided asset to replace the domain name with this CDN. For example:

http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css

should become:

//assets.euractiv.com/cdn/bootstrap/3.3.5/css/bootstrap.css

The supported libraries are:

  • Bootstrap (bootstrapcdn)
  • Bootswatch (bootstrapcdn)
  • Font Awesome (bootstrapcdn)
  • jQuery (code.jquery.com)
  • Google Analytics (ga.js)
  • CreateJS
  • JS delivr (jsdelivr.com) [most likely match]

In most cases, it is better to reference minified resources directly if the source offers them. If not, you can prepend the requested file with min/ to have this CDN do the minifcation for you. The code from the quick start example would change:

//assets.euractiv.com/cdn/bootstrap/3.3.5/css/bootstrap.css

to:

//assets.euractiv.com/cdn/min/bootstrap/3.3.5/css/bootstrap.css

Configuration

Configuration is located in the file /config/cdn.php. If you do not have the ability to modify this file, contact your administrator to have options changed. The configuration file should contain an array with the name $config containing the following offsets:

NameTypeDescriptionCurrent Setting
example_filestringA file to use for the "Quick Start" example
bootstrap/3.3.5/css/bootstrap.css
domain_maparrayThe maps of files to the source CDN domain. The format is an array of arrays, where each item has the following entries:
  • name: the human readable name for the CDN
  • regex: the regular expression to test requested files against to match this CDN
  • domain: the scheme/domain to prepend in front of the requested file to create the fully-qualified URL to the source file.
Login to view this setting
callmap_driverstringThe callmap driver to use, either "sqlite", "fsstore" or "noop"
noop
callmap_labelsarrayLabels for the callmap, where the key is the regular expression to match and the value is the label to useLogin to view this setting
callmap_visualize_defaultarrayNodes to visualize by defaultLogin to view this setting
callmap_probabilityintegerProbability that a given hit will log. Important for high traffic sites. Set higher for lower probability.
1000
http_allowed_domainsarrayAllowed domains for fetching assets or generating URLsLogin to view this setting
http_allowed_urlsarraySpecified URLs or regular expressions of specified URLs match for fetching assets or generating URLsLogin to view this setting
http_connect_timeoutintegerThe amount of time, in seconds, that cURL should wait before returning an error status. 15 is a good value for most cases.
15
api_keystringThe key to access protected API calls. This key should only be used in server-to-server communication to avoid exposing it to the broader internet. In requests, the key can be set in the query as the "api_key" value (eg http://example.com?api_key=keyboard_cat), in a POST request body as the "api_key" value, or as a header with the name "X-Vsac-Api-Key".Login to view this setting