Minification of JS and CSS files is one of the important performance improvement parameter which Oracle recommends. Also by web standards, all the files (JS/CSS) deployed on production servers should be minified.
First of all, we can start with basics. What is minification?
Minify or Minification of files means removing extra spaces, tab spaces, gaps, comments and redudant code lines. By removing lines of code which are added only for readibility purposes, we decrease the overall size of the files.
With size being decreased of all files, it decreases total load on network. Which in turn improves server performance and loads application faster.
Siebel OpenUI comes with lot of javascripts. Javascripts provided by siebel are already minified. However, for all the custom javascripts ( PR/PM/Third party plugins) created by developers of Siebel OpenUI for their clients needs to be minified.
There are few options to minify files:
1. Use online tools which can minify files. However, there is a risk involved. The files are uploaded on third party servers and the business logic written exclusively for your clients can be shared on online portals. There is huge business risk. To avoid it, there is another option as mentioned in point
2. Manually minify all files on your local PC: Removing comments, spaces, gaps and redundant code lines manually - each file is huge amount of task. Also with manual intervention, the chance of mistakes increases drastically. Developers can by mistake remove lines which can break functionality.
Hence, We would like to present you a better option - It combines both the points: Automatic minification of all JS and CSS files in just one click. It happens in your local windows machine OR in your Linux/UNIX servers. Hence there is no risk of deploying codebase on external 3rd party servers.
Here's the step by step Tutorial :
Step 1: Download YUICompressor Jar file.
To Download the file, Click here
This is again Oracle recommended tool and hence you can use it without giving it another thought.
Step 2: Create Batch Script OR Shell script:
=> Batch Script:
If you are using Windows machine in your local or server, you can write batch script which will help you run one click minification.
Store this code in .bat file and Run this file from any location. In one click of this batch script, all the JS and CSS files will be minified and store in location mentioned by you.
This Code will go through all the CSS and JS files one by one and minify it. The process is fast too and it takes less than 5 seconds to minify 10 JS files.
To know more about --nomunge --preserve-semi --disable-optimizations parameters used, you can check YUICompressor Documentation here
=> Shell Script:
If you wish to use this on linux/UNIX servers, here's the code you can write in shell scripting -> .sh files.
This is just sample code base. You can obviously improve the shell or batch script as per your coding requirements.
Also, you can set the variables like yui,css,js above as per the location in your server where your files are stored. You can also automate this with your cron jobs and run on regular intervals. Or just run on demand and it will minify all the files in one GO.
Benefits:
=> It happens automatically. No Manual Intervention needed. Just one click and all your custom CSS and JS files will be minified quickly.
=> Not OS dependent. You can run the code in Windows or Linux or UNIX environments.
=> Completely safe and No Risk. It happens in your client network and their environment hence, code is not exposed in third party online websites.
=> Fast and Secure. Oracle Recommended Tool.
=> Possibilities to automate this batch or shell script during deployments via Jenkins or other pipeline automation tools.
Hope this saves lot of time in your project for some other productive work!
First of all, we can start with basics. What is minification?
Minify or Minification of files means removing extra spaces, tab spaces, gaps, comments and redudant code lines. By removing lines of code which are added only for readibility purposes, we decrease the overall size of the files.
With size being decreased of all files, it decreases total load on network. Which in turn improves server performance and loads application faster.
Siebel OpenUI comes with lot of javascripts. Javascripts provided by siebel are already minified. However, for all the custom javascripts ( PR/PM/Third party plugins) created by developers of Siebel OpenUI for their clients needs to be minified.
There are few options to minify files:
1. Use online tools which can minify files. However, there is a risk involved. The files are uploaded on third party servers and the business logic written exclusively for your clients can be shared on online portals. There is huge business risk. To avoid it, there is another option as mentioned in point
2. Manually minify all files on your local PC: Removing comments, spaces, gaps and redundant code lines manually - each file is huge amount of task. Also with manual intervention, the chance of mistakes increases drastically. Developers can by mistake remove lines which can break functionality.
Hence, We would like to present you a better option - It combines both the points: Automatic minification of all JS and CSS files in just one click. It happens in your local windows machine OR in your Linux/UNIX servers. Hence there is no risk of deploying codebase on external 3rd party servers.
Here's the step by step Tutorial :
Step 1: Download YUICompressor Jar file.
To Download the file, Click here
This is again Oracle recommended tool and hence you can use it without giving it another thought.
Step 2: Create Batch Script OR Shell script:
=> Batch Script:
If you are using Windows machine in your local or server, you can write batch script which will help you run one click minification.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | set yui="<Location of YUI Jar File downloaded above>" set css=<Location of CSS files present:Example: D:\Siebel\Minify\CSS> set js=<Location of CSS files present:Example: D:\Siebel\Minify\JS> set css_min=<Location where Minified files will be stored after Minification:Example: D:\Siebel\Minify\CSS_min> set js_min=<Location where Minified files will be stored after Minification: Example: D:\Siebel\Minify\JS_Min> set jsext=.js set cssext=.css pushd %css% for %%b in (*%cssext%) do java -jar %yui% --type css %%b > %css_min%\%%b pushd %js% for %%a in (*%jsext%) do java -jar %yui% --type js --nomunge --preserve-semi --disable-optimizations %%a > %js_min%\%%a |
Store this code in .bat file and Run this file from any location. In one click of this batch script, all the JS and CSS files will be minified and store in location mentioned by you.
This Code will go through all the CSS and JS files one by one and minify it. The process is fast too and it takes less than 5 seconds to minify 10 JS files.
To know more about --nomunge --preserve-semi --disable-optimizations parameters used, you can check YUICompressor Documentation here
=> Shell Script:
If you wish to use this on linux/UNIX servers, here's the code you can write in shell scripting -> .sh files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | yui="/application/siebel/Minify/yuicompressor-2.4.8.jar" css=/application/siebel/Minify/CSS_Custom js=/application/siebel/Minify/PM_PR_PW_CUST css_min=/application/siebel/Minify/CSS_Custom_MIN js_min=/application/siebel/Minify/PM_PR_PW_CUST_MIN minify_path=/application/siebel/Minify jsext=.js cssext=.css cd $css for filename in $css/*; do file=$(basename "$filename") java -jar $yui --type css $file> $css_min/$file done cd $js for filename in $js/*.js; do file=$(basename "$filename") java -jar $yui --type js --nomunge --preserve-semi --disable-optimizations $file> $js_min/$file done cd $minify_path |
This is just sample code base. You can obviously improve the shell or batch script as per your coding requirements.
Also, you can set the variables like yui,css,js above as per the location in your server where your files are stored. You can also automate this with your cron jobs and run on regular intervals. Or just run on demand and it will minify all the files in one GO.
Benefits:
=> It happens automatically. No Manual Intervention needed. Just one click and all your custom CSS and JS files will be minified quickly.
=> Not OS dependent. You can run the code in Windows or Linux or UNIX environments.
=> Completely safe and No Risk. It happens in your client network and their environment hence, code is not exposed in third party online websites.
=> Fast and Secure. Oracle Recommended Tool.
=> Possibilities to automate this batch or shell script during deployments via Jenkins or other pipeline automation tools.
Hope this saves lot of time in your project for some other productive work!
No comments:
Post a Comment