JavaScript (JS) compression/obfuscation/formatting batch processing tool _ javascript skills

Source: Internet
Author: User
All functions of this tool are implemented by ttp: jscompress. sinaapp. comapi processing. (including now can use this online compression) Yesterday shared the http://jscompress.sinaapp.com/This gadgets, found that you are still very fond.

So today, I converted it into json. I used json to transmit data and opened APIs.

All functional implementations of this tool are handled by the http://jscompress.sinaapp.com/api. (including the online compression that can be used now)
All data exchanges are processed by the http post input and json is used as the data output format.

API parameters: http://jscompress.sinaapp.com/api? Get = {type} & code = (code) & type = {compress only}


Get = {type}, {type} is an optional compress (Compressed) format (formatted) shuffle (obfuscated)
Code = (code), (code) is the source code of necessary source code. JavaScript
Type = {compress}, {compress} note that this parameter takes effect only when compression is enabled. Optional values: 1 (default compression) 2 (YUI compression) 3 (GC compression)


Example: Use CURL... POST

Http://jscompress.sinaapp.com/api? Get = compress & code = var a = 1; var B = 2; & type = 2


If the execution is successful, the following result is returned:

{"code":"var a=1,b=2;\n","original_size":"16 Byte","now_size":"13 Byte","status":"Closure Compiler \u538b\u7f29\u5b8c\u6210.","minify":"81.25%"}

Then I wrote a PHP file, which can call the api of this website to compress or confuse all js files in the entire directory, format them, and save them to a new directory.

This makes it easy for students who are lazy to upload files ~~

Direct: jstools.rar
Highlight

The Code is as follows:

 '. /', // Path of the script to be processed... 'compiled '=> '. /compiled/', // path of the new file after processing... 'type' => 'companys', // optional compress (Compressed) format (formatted) shuffle (obfuscation) 'is _ merger '=> true, // whether to merge all files for processing (compression, formatting, and obfuscation) 'engine' => '1' // This option is only valid when type is compress, 1 (default) 2 (yui) 3 (Closure Compiler)/* the compression of yui and Google Closure Compiler is irreversible. Generally, obfuscation is not recommended if you use the default one. */) {if (is_dir ($ options ['basepath']) {if ($ dh = opendir ($ options ['basepath'])) {While ($ file = readdir ($ dh ))! = False) {if (strpos ($ file, '. js ')! = False & strpos ($ file ,'. min. js') === false) {$ js [] = $ file ;}} closedir ($ dh) ;}} if ($ options ['is _ merger ']) {foreach ($ js as $ jsfile) {$ jscode. = file_get_contents ($ jsfile ). ';} $ jscode = json_decode (api ($ jscode, $ options ['type'], $ options ['engine']), true ); file_put_contents ($ options ['compiled ']. 'All. min. js', $ jscode ['code']);} else {foreach ($ js as $ jsfile) {$ jscode = json_decode (api (file_get_contents ($ jsfile ), $ options ['type'], $ options ['engine']), true); file_put_contents ($ options ['computed']. str_replace ('. js ','. min. js', $ jsfile), $ jscode ['code']) ;}} function api ($ code, $ type, $ engine) {$ ch = curl_init (' http://jscompress.sinaapp.com/api '); Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, 'Get = '. $ type. '& code = '. urlencode ($ code ). '& type = '. $ engine); $ output = curl_exec ($ ch); curl_close ($ ch); return $ output;} JsTools ();?>

The above content is the JavaScript (JS) compression/obfuscation/formatting of the batch processing tool _ javascript skills. For more information, please follow the PHP Chinese Network (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.