Skip to content

mchv/play2-cloudfront

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudfront module for play 2

Cloudfront enables to set up a CDN easily. This module helps to integrate your Cloudfront CDN with play.

Setting up with sbt

Configure a new resolver:

resolvers += "Mariot Chauvin repository" at "http://mchv.me/repository"

Add the library dependency:

libraryDependencies += "mchv" %% "play2-cloudfront" % "1.1"

Use a custom controller

Create a new file named RemoteAssets.scala that contains:

package controllers

import controllers._

object RemoteAssets extends Remote {
    def call(file:String) = {
        controllers.routes.RemoteAssets.at(file)
    }
}

Update the router file with the call to your custom controller for your assets:

# Map static resources from the /public folder to the /assets URL path
GET     /assets/*file               controllers.RemoteAssets.at(path="/public", file)

Update your views to refer to your controller to fetch the url:

@(title: String)(content: Html)

<!DOCTYPE html>

<html>
    <head>
        <title>@title</title>
        <link rel="stylesheet" media="screen" href="@RemoteAssets.url("stylesheets/main.css")">
        <link rel="shortcut icon" type="image/png" href="@RemoteAssets.url("images/favicon.png")">
        <script src="@RemoteAssets.url("javascripts/jquery-1.9.1.min.js")" type="text/javascript"></script>
    </head>
    <body>
        @content
    </body>
</html>

Configure the module with your cloudfront settings

Add your Cloudfront url to the application.conf:

cdn-url="http://d7471vfo50fqt.cloudfront.net"

More

The module is based on James Ward tutorial If you want to know more or avoid the dependency, please read it.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages