I have always wanted to compress the js and css in the project, and I finally did it today.
First let’s talk about a few issues to pay attention to. The goals will affect your corresponding solutions:
1. Whether the compressed file should directly overwrite the old file
2. Single compressed file is overwritten. Name it, or rename the entire directory while keeping the file name unchanged
3. Deployment access and switching issues
4. After compression, should it be uploaded to a remote repository such as git?
For example
C:/js
a.js,a.css
Method 1, overwrite directly, the directory and file names will not change.
Method 2, no overwriting, still in the same directory.
C:/js/a.min.js
Method three, change the directory with the same name
C:/js2/a.js
---------- --------------------
During the development process, you may be used to using uncompressed files, but you may want to use compressed files after going online.
Writing this article is really confusing because there are too many scenes and I feel so tired thinking about them.
-------------------------------
There are many compression tools and methods:
Method 1: Use yuicompress. You can use the command line, such as java, nodejs, etc.
Method 2: Use tbcompress, which is said to be modified by Taobao based on yuicompress.
Method 3: Use the source code directly to control compression in the java program.
-------------------------------
Finally, let me talk about my current approach:
1. In the local Java project, there is a compression tool class.
Compress all the css and js files in the a directory and put them in the b directory.
2. Both a and b are submitted to git.
3. The static resource URL is variable.
frontStaticUrl=http://a.com:80/a
can be changed to
frontStaticUrl=http://a.com:80/b
to achieve the original file and compressed version Switch
-------------------------------
The above method is bad.
1. If the original file changes, the compressed file must be generated again.
Of course, for the sake of simplicity, only when it is determined that the deployment needs to go online, the compression will be performed and submitted to git.
2. Because it is a program, it has higher requirements for the execution environment.
For example, if another project or a non-java project also wants to compress, it will not be possible.
----------------------------------
Wuhan Jiutianniao-Wuhan's leading mobile Internet system development Shang
Jiutianniao Q&A-http://ask.jiutianniao.com
Jiutianniao Blog-http://blog.jiutianniao.com
Jiutianniao official website-construction in, stay tuned