1. Css

We’ll use LESS CSS, all less sources are defined in the app/assets, and they will be

compiled to standard css by the build process.

Below are steps to use the less css.

a.   add sbt-less plugin to your project’s plugins.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.0")

b.   enable the sbt-web plugin for your project

Note: sbt-web is auto enabled in play 2.3.x, we do not need this step if our app is

based on play2.3.x

lazy val root = (project in file(".")).enablePlugins(SbtWeb)

c.  tell less compiler to compile related less sources

add the following lines to build.sbt of your project.

includeFilter in (Assets, LessKeys.less) := "*.less"

excludeFilter in (Assets, LessKeys.less) := "_*.less"

d.  enable compress

add the following line to build.sbt of your project.

LessKeys.compress in Assets := true

for step c & d, we can also configure these settings in Build.Scala, which is

equal to  built.sbt

e.   create less file in your assets/css(e.g.   assets/css/demo.less), you can import other

less file.

e.g.  @import "lib/bootstrap/less/bootstrap.less";

f.    use the less in your page, just add the stylesheet reference to demo.css

e.g. <link rel="stylesheet" type="text/css"  href=”css/demo.css”/>

h.   LESS sources are compiled automatically during an assets command, or when

you  refresh any page in your browser while you are running in development mode.

i.     More online resource

AssetsLess

sbt-less plugin

Javascript

We’ll use RequireJS(a JavaScript file and module loader) to modularize our

JavaScript.  Using RequireJS makes it is possible to resolve and load javascript modules

on the client side while allowing server side optimization. For server side optimization

module dependencies may be minified and combined, and we can use sbt-rjs to do the

optimization.

Using RequireJS, we should write our js in modular. Below is an example on how to use

requirejs.

//demouser/UserController.js

define([], function(){

function UserController($scope, $http){

$scope.user = {"email":"", "name":"", "id":null};

$scope.load = function(){

$http.get('user/list')

.success(function(resp){

$scope.users = resp;

})

};

$scope.load();

}

UserController.$inject = ['$scope', '$http'];

return UserController;

});

//userMain.js,  module loader

requirejs.config({

paths: {

'angular': ['../lib/angularjs/angular'],

'angular-route': ['../lib/angularjs/angular-route'],

},

shim: {

'angular': {

exports : 'angular'

},

'angular-route': {

deps: ['angular'],

exports : 'angular'

}

}

});

require(['angular', './demouser/UserController'],

function(angular, UserController) {

var app = angular.module('app', []);

app.controller("UserController", UserController);

angular.bootstrap(document, ['app']);

});

//page

<html>

<body>

…………………………..

<script data-main=’userMain.js’ src=”lib/requirejs/require.js”></script>

</body>

</html>

Server Side optimization

  1. add sbt-rjs plugin to your plugins.sbt of your project

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")

2. configure sbt-rjs  in Build.scala

includeFilter in rjs := GlobFilter("*.js"),

RjsKeys.paths := Map(

    "angular" -> ("../lib/angularjs/angular", "../lib/angularjs/angular")

),

RjsKeys.modules := Seq(

//WebJs.JS.Object("name" -> "angularDemoMain"),//do optimization for module

   WebJs.JS.Object("name" -> "userMain")

)

3.  add the plugin to the asset pipeline

pipelineStages := Seq(rjs)

4. generate the minified & combined js
              The RequireJS optimizer shouldn’t generally kick-in until it is time to perform a  
              deployment. i.e. by running start, state, dist tasks.

Play - js/css concatenation & minify的更多相关文章

  1. grunt 压缩js css html 合并等配置与操作详解

    module.exports = function(grunt){ //1.引入 grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTa ...

  2. electron之Windows下使用 html js css 开发桌面应用程序

    1.atom/electron github: https://github.com/atom/electron 中文文档: https://github.com/atom/electron/tree ...

  3. JS/CSS缓存杀手——VS插件

    背景 前些天去考科目二,感觉经历了一场不是高考却胜似高考的考试(10年前的5分之差, 还是难以释怀)!    一行八人,就我学的时间最少(4天,8人一辆车),教练都觉得我肯定还得再来一次! 靠着运气和 ...

  4. gulp实现打包js/css/img/html文件,并对js/css/img文件加上版本号

    参考打包教程: http://www.cnblogs.com/tugenhua0707/p/4069769.html http://www.cnblogs.com/tugenhua0707/p/498 ...

  5. 配置springMVC之后,引入js,css等资源处理

    配置了sringMVC之后,要引入js,css处理: 做法1:在<%page %>下面增加: <%@ taglib prefix="yesurl" uri=&qu ...

  6. springmvc js/css路径问题

    ①No mapping found for HTTP request with URI[/msm2/css/login2.css] in DispatcherServlet with name 'sp ...

  7. iOS之在webView中引入本地html,image,js,css文件的方法 - sky//////////////////////////////////////ZZZZZZZZZZZZZZZ

    iOS之在webView中引入本地html,image,js,css文件的方法   2014-12-08 20:00:16CSDN-sky_2016-点击数:10292     项目需求 最近开发的项 ...

  8. springMVC下jsp引用外部js,css等静态资源的解决方法

    直入主题. 1. web.xml对springMVC配置如下: <servlet> <description>Spring MVC配置</description> ...

  9. 在Sublime Text 3 中安装SublimeLinter,Node.js进行JS&CSS代码校验

    转载自:http://www.wiibil.com/website/sublimelinter-jshint-csslint.html 在Sublime Text中安装SublimeLinter,No ...

随机推荐

  1. DELL笔记本拆机添加内存条

    在笔记本后面拧开7个螺丝 然后打开后盖 掰开卡口,内存条会弹出,此时按住内存条两侧的缺口往外用力就可以拔出内存条. 装入内存条时,先插入内存条,按下即可.

  2. Devexpress之dxErrorProvider

    DXErrorProvider:错误提示控件,用法类似于VS的winform控件中的ErrorProvider. 下面为一个使用实例,验证文本框输入是否为数字: ①.添加System.Text.Reg ...

  3. 【单页应用】view与model相关梳理(转载)

    [单页应用]view与model相关梳理 前情回顾 根据之前的学习,我们形成了一个view与一个messageCenterview这块来说又内建了一套mvc的东西,我们这里来理一下首先View一层由三 ...

  4. Python手动构造Cookie模拟登录后获取网站页面内容

    最近有个好友让我帮忙爬取个小说,这个小说是前三十章直接可读,后面章节需要充值VIP可见.所以就需要利用VIP账户登录后,构造Cookie,再用Python的获取每章节的url,得到内容后再使用 PyQ ...

  5. Java---XML的解析(1)-DOM解析

    本章只讲DOM解析.接下来还会学习Dom4j和StAX 解析技术 DOM解析: DOM解析一次将所有的元素全部加载到内存中:如有以下XML文档: <user> <name>Ja ...

  6. Bzoj 1901: Zju2112 Dynamic Rankings 树套树,线段树,平衡树,Treap

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 6471  Solved: 2697[Su ...

  7. Bzoj 1046: [HAOI2007]上升序列 二分,递推

    1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3671  Solved: 1255[Submit][Stat ...

  8. Bzoj 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 最短路,floyd

    1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 5 ...

  9. MySQL数据库建立外键失败的原因总结

    在MySQL数据库创建外键时,经常会发生一些错误,这是一件很令人头疼的事.一个典型的错误就是:Can’t create table... 的错误.在很多实例中,这种错误的发生都是因为mysql一直以来 ...

  10. hdu 4712 (随机算法)

    第一次听说随机算法,在给的n组数据间随机取两个组比较,当随机次数达到一定量时,答案就出来了. #include<stdio.h> #include<stdlib.h> #inc ...