Play - js/css concatenation & minify
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
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
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的更多相关文章
- grunt 压缩js css html 合并等配置与操作详解
module.exports = function(grunt){ //1.引入 grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTa ...
- electron之Windows下使用 html js css 开发桌面应用程序
1.atom/electron github: https://github.com/atom/electron 中文文档: https://github.com/atom/electron/tree ...
- JS/CSS缓存杀手——VS插件
背景 前些天去考科目二,感觉经历了一场不是高考却胜似高考的考试(10年前的5分之差, 还是难以释怀)! 一行八人,就我学的时间最少(4天,8人一辆车),教练都觉得我肯定还得再来一次! 靠着运气和 ...
- gulp实现打包js/css/img/html文件,并对js/css/img文件加上版本号
参考打包教程: http://www.cnblogs.com/tugenhua0707/p/4069769.html http://www.cnblogs.com/tugenhua0707/p/498 ...
- 配置springMVC之后,引入js,css等资源处理
配置了sringMVC之后,要引入js,css处理: 做法1:在<%page %>下面增加: <%@ taglib prefix="yesurl" uri=&qu ...
- springmvc js/css路径问题
①No mapping found for HTTP request with URI[/msm2/css/login2.css] in DispatcherServlet with name 'sp ...
- iOS之在webView中引入本地html,image,js,css文件的方法 - sky//////////////////////////////////////ZZZZZZZZZZZZZZZ
iOS之在webView中引入本地html,image,js,css文件的方法 2014-12-08 20:00:16CSDN-sky_2016-点击数:10292 项目需求 最近开发的项 ...
- springMVC下jsp引用外部js,css等静态资源的解决方法
直入主题. 1. web.xml对springMVC配置如下: <servlet> <description>Spring MVC配置</description> ...
- 在Sublime Text 3 中安装SublimeLinter,Node.js进行JS&CSS代码校验
转载自:http://www.wiibil.com/website/sublimelinter-jshint-csslint.html 在Sublime Text中安装SublimeLinter,No ...
随机推荐
- 微软开放技术开发了适用于 Windows Azure 移动服务的开源 Android SDK
发布于 2014-02-10 作者 陈 忠岳 为进一步实现连接微软与非微软技术的目标,微软开放技术有限公司开发了适用于 Windows Azure 移动服务的 Android SDK,由Scot ...
- Android——service重启
一.在application中注册消息监听 public class BackgroundServiceApplication extends Application { @Override publ ...
- 排列的Java递归语言实现
在做算法题的时候,发现排列经常被使用到,是一个重要的知识点, 下面是博主修改过的代码,初学者,如有不足,欢迎指出 import java.util.ArrayList; import java.uti ...
- head tail 命令
[一]从第3000行开始,显示1000行.即显示3000~3999行 cat filename | tail -n +3000 | head -n 1000 [二]显示1000行到3000行 cat ...
- 什么时候使用Shell
因为Shell似乎是各UNIX系统之间通用的功能,并且经过了POSIX的标准化.因此,Shell脚本只要“用心写”一次,即可应用到很多系统上.因此,之所以要使用Shell脚本是基于: 简单性:Shel ...
- Javascript类型——boolean类型
布尔值在Javascript中有两个值:true和false. 布尔值和其他数据类型的转换关系 数据类型 true false boolean true false String 任何非空字符串 &q ...
- Android.mk各种文件编译汇总
一.源代码编译 1.1 so预编译 LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := libAppArea LOCAL ...
- .h头文件 .lib库文件 .dll动态库文件之间的关系
.h头文件是编译时必须的,lib是链接时需要的,dll是运行时需要的. 附加依赖项的是.lib不是.dll,若生成了DLL,则肯定也生成 LIB文件.如果要完成源代码的编译和链接,有头文件和lib就够 ...
- Android 获取运营商信息(完整版)-解决高通,MTK等双卡问题
由于国内的运营商问题,双卡手机获取IMSI号问题要根据厂商API 来实现. 下面我们就来做一套完整的分析运营商获取IMSI号逻辑. 1,首先我们要判断手机的平台. 1.1,判断手机是否MTK平台 1 ...
- php的ob_flush和flush(转)
php.ini中 output_buffering = off 关闭php的缓存 implicit_flush = Off php不会立即输出到浏览器.如果是ON,相当于每次ECHO 立刻执行一个FL ...