Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Beego Compress provides an automated system for compressing Css and JavaScript files

NotificationsYou must be signed in to change notification settings

beego/compress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Beego Compress provides an automated system for compressing JavaScript and Css files

It default useGoogle Closure Compiler for js, andYui Compressor for css

Sample Usage with Beego

After create a config file, you can simple use it in beego.

Movecompiler.jar andyuicompressor.jar to your beego app path. Parallel with static path.

BTW: Of course you can integrated it with other framework or use it as a command line tool.

funcSettingCompress() {// load json config fileisProductMode:=falsesetting,err:=compress.LoadJsonConf("conf/compress.json",isProductMode,"http://127.0.0.1/")iferr!=nil {beego.Error(err)return}// after use this api, can run command from shell.setting.RunCommand()ifisProductMode {// if in product mode, can use this api auto compress filessetting.RunCompress(true,false,true)}// add func to FuncMap for template usebeego.AddFuncMap("compress_js",setting.Js.CompressJs)beego.AddFuncMap("compress_css",setting.Css.CompressCss)}

In tempalte usage

...<head>...{{compress_css "lib"}}{{compress_js "lib"}}{{compress_js "app"}}</head>...

Congratulations!! Let's see html results.

Render result when isProductMode isfalse

<!-- Beego Compress group `lib` begin --><linkrel="stylesheet"href="http://127.0.0.1/static_source/css/bootstrap.css?ver=1382331000"/><linkrel="stylesheet"href="http://127.0.0.1/static_source/css/bootstrap-theme.css?ver=1382322974"/><linkrel="stylesheet"href="http://127.0.0.1/static_source/css/font-awesome.min.css?ver=1378615042"/><linkrel="stylesheet"href="http://127.0.0.1/static_source/css/select2.css?ver=1382197742"/><!-- end --><!-- Beego Compress group `lib` begin --><scripttype="text/javascript"src="http://127.0.0.1/static_source/js/jquery.min.js?ver=1378644427"></script><scripttype="text/javascript"src="http://127.0.0.1/static_source/js/bootstrap.js?ver=1382328826"></script><scripttype="text/javascript"src="http://127.0.0.1/static_source/js/lib.min.js?ver=1382328441"></script><scripttype="text/javascript"src="http://127.0.0.1/static_source/js/jStorage.js?ver=1382271840"></script><!-- end --><!-- Beego Compress group `app` begin --><scripttype="text/javascript"src="http://127.0.0.1/static_source/js/main.js?ver=1382195678"></script><scripttype="text/javascript"src="http://127.0.0.1/static_source/js/editor.js?ver=1382342779"></script><!-- end -->

Render result when isProductMode istrue

<linkrel="stylesheet"href="http://127.0.0.1:8092/static/css/lib.min.css?ver=1382346563"/><scripttype="text/javascript"src="http://127.0.0.1:8092/static/js/lib.min.js?ver=1382346557"></script><scripttype="text/javascript"src="http://127.0.0.1:8092/static/js/app.min.js?ver=1382346560"></script>

Config file

Full config file example.

note: All json key are not case sensitive

compress.json:

{"Js": {// SrcPath is path of source file"SrcPath": "static_source/js",// DistPath is path of compressed file"DistPath": "static/js",// SrcURL is url prefix of source file"SrcURL": "static_source/js",// DistURL is url prefix of compressed file"DistURL": "static/js","Groups": {// lib is the name of this compress group"lib": {// all compressed file will combined and save to DistFile"DistFile": "lib.min.js",// source files of this group"SourceFiles": ["jquery.min.js","bootstrap.js","lib.min.js","jStorage.js"],// skip compress file list"SkipFiles": ["jquery.min.js","lib.min.js"]},"app": {"DistFile": "app.min.js","SourceFiles": ["main.js","editor.js"]}}},"Css": {// config of css is same with js"SrcPath": "static_source/css","DistPath": "static/css","SrcURL": "static_source/css","DistURL": "static/css","Groups": {"lib": {"DistFile": "lib.min.css","SourceFiles": ["bootstrap.css","bootstrap-theme.css","font-awesome.min.css","select2.css"],"SkipFiles": ["font-awesome.min.css","select2.css"]}}}}

Command mode

when use apisetting.RunCommand()

$ go build app.go$ ./app compresscompress command usage:    js     - compress all js files    css    - compress all css files    all    - compress all files$ ./app compress js -hUsage of compress command: js:  -force=false: force compress file  -skip=false: skip all cached file  -v=false: verbose info$ ./app compress css -hUsage of compress command: css:  -force=false: force compress file  -skip=false: skip all cached file  -v=false: verbose info
use -force for re-create dist file but not skip cached.use -skip can skip all cached file and re-compress.

Custom Compress

All api can view inGoWalker

  • TmpPath is default path of cached files.
  • Can modifyJsFilters / CssFilters use your compress filter.
  • Can modify JsTagTemplate / CssTagTemplate with your<script><link> tag.

Contact and Issue

All beego projects need your support.

Any suggestion are welcome, pleaseadd new issue let me known.

LICENSE

beego compress is licensed under the Apache Licence, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html).

About

Beego Compress provides an automated system for compressing Css and JavaScript files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp