

[Golang] Online Concatenate and Compress JavaScript Files
source link: http://siongui.github.io/2016/03/07/go-online-concatenate-and-compress-js-files/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[Golang] Online Concatenate and Compress JavaScript Files
March 07, 2016
Concatenate and compress JavaScript files via Golang and online Google Closure Compiler.
package main import ( "io/ioutil" "net/http" "net/url" "path" ) func minjs(baseDir string, jsFiles []string, outputPath string) { var jsCode []byte for _, file := range jsFiles { jsPath := path.Join(baseDir, file) println("concatenating " + jsPath + " ...") b, err := ioutil.ReadFile(jsPath) if err != nil { panic(err) } jsCode = append(jsCode, b...) } params := url.Values{} //params.Set("code_url", "https://github.com/twnanda/twnanda/raw/master/theme/javascript/tongwen_core.js") //params.Set("code_url", "https://github.com/twnanda/twnanda/raw/master/theme/javascript/tongwen_table_ps2t.js") //params.Set("code_url", "https://github.com/twnanda/twnanda/raw/master/theme/javascript/tongwen_table_pt2s.js") //params.Set("code_url", "https://github.com/twnanda/twnanda/raw/master/theme/javascript/tongwen_table_s2t.js") //params.Set("code_url", "https://github.com/twnanda/twnanda/raw/master/theme/javascript/tongwen_table_t2s.js") params.Set("js_code", string(jsCode)) params.Set("compilation_level", "SIMPLE_OPTIMIZATIONS") params.Set("language", "ECMASCRIPT5") params.Set("output_format", "text") params.Set("output_info", "compiled_code") println("\nCompressing combined js online ...") resp, err := http.PostForm("https://closure-compiler.appspot.com/compile", params) if err != nil { panic(err) } defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) if err != nil { panic(err) } ioutil.WriteFile(path.Join(baseDir, outputPath), b, 0644) } func main() { baseDir := "dictionary" jsFiles := []string{ "common/app/scripts/services/data/dicBooks.js", "common/app/scripts/services/data/succinctTrie.js", "common/app/scripts/services/data/i18nStrings.js", "app/scripts/app.js", "app/scripts/controllers.js", "app/scripts/directives/inputSuggest.js", "app/scripts/directives/draggableAndEvents.js", "common/app/scripts/services/paliWordJson.js", "common/app/scripts/services/shortExp.js", "common/app/scripts/services/ngBits.js", "common/app/scripts/services/wordSearch.js", "common/app/scripts/directives/dropdown.js", "common/app/scripts/filters/expOrder.js", "common/app/scripts/i18n.js", } minjs(baseDir, jsFiles, "app/all_compiled.js") }
Recommend
-
6
Want to compress your pdf files ? Are you tired of scanning images and trying to shrink them under 25 mbs just so you can send them via email ? Look no further, I am here to save you from this trouble. (that...
-
8
How does yui-compressor compress the javascript and css files? advertisements I am curious to understand what all things a...
-
7
6 Ways to Compress Image Files in Windows 11 and 10 By Jack Slater Published 11 hours ago Compressing image files is a g...
-
10
[Makefile] Online Concatenate and Compress JavaScript Files December 26, 2016...
-
6
[Python] Online Concatenate and Compress JavaScript Files February 26, 2016...
-
12
[Bash] Online Concatenate and Compress JavaScript Files December 25, 2016...
-
3
[Python] Concatenate JavaScript Files February 25, 2016 Concatenate
-
3
[Golang] Concatenate JavaScript Files March 06, 2016 Concatenate
-
4
RESEARCHUsing AI to compress audio files for quick and easy sharing October 25, 2022
-
6
Calling the Command Line Tool FFmpeg to Concatenate Video Files » Stuart’s MATLAB Videos I often need to call external command line tools fr...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK