Giter VIP home page Giter VIP logo

play-cdnassets's Introduction

CdnAssets for Play Framework 2.x (Scala)

CdnAssets.scala is a simple replacement for Play Framework’s Assets.at() to enable loading static assets such as JavaScript, CSS, images etc. from a content delivery network (e.g. CloudFront). Whilst in development mode assets are loaded from localhost with an added timestamp as query string to prevent assets from being cached.

CdnAssets has been used successfully with Play Framework 2.2 and 2.3.

Instructions

The following instructions apply to a standard Play Framework 2.x installation.

  • Copy CdnAssets.scala to /app/controllers/.
  • In your views replace @Assets.at("filename") with @CdnAssets.at("filename") (see sample-view.scala.html).
  • Add assetscdn="//xxxxxxxxxxx.cloudfront.net" and assetsversion="1" to your /conf/application.conf (see sample.conf).
  • Make sure your development assets are stored in /public/dev/.
  • Make sure your production assets are stored in /public/1/.

Whenever you deploy a new version of your assets, bump the assetsversion number in the config file and store the new assets in /public/{version number}/. A Grunt task can make this a simple task.

The benefits of putting an assets version number into the path is, old assets will no longer be loaded from cache – neither from browser cache nor from the CDN’s caches. You don’t have to invalidate the objects of the CDN, which can take a very long time and may involve cost. You can increase max-age cache headers of your assets for better performance.

Limitations

There is no equivalent for Assets.at(path: String, file: String).

play-cdnassets's People

Contributors

manc avatar levinotik avatar

Stargazers

Joseph Chiocchi avatar  avatar

Watchers

 avatar James Cloos avatar

Forkers

levinotik

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.