Set the css_fast_load parameter in Liferay, minifyType, and Minifier Filter

Source: Internet
Author: User


Introduction:

For debugging purposes, most people will set css_fast_load to 0, so that they can see the loading of each separate css style file. On the product server, in order to speed up, if this parameter is set to 1 and multiple css files are merged into a single file, what is the mystery of this?


Debugging analysis:

Taking advantage of the free time on the last day of Sprint, I was lucky enough to analyze the Liferay source code and find out the secrets.


When the request is http: //

During callback, it will enter the getStaticResourceURL method of PortalImpl:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252M351-0.png "title =" 131.png"/>


It first obtains ThemeDisplay from the request object in Row 3, and then obtains Theme and ColorTheme from ThemeDisplay.


Then, it begins to attach parameters to our request resources.


First, it adds a question mark (?) to line 1-3532 (?) Used to distinguish between parameters and the preceding request path.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252H007-1.png "title =" 132.png"/>


Then add the browserId parameter to line 3534-3541, which is obtained through the BrowserSnifferUtil tool class. Because this is not the focus of our discussion, we will not expand it.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252H5K-2.png "title =" 133.png"/>


Add the themeId parameter to the 3543-3550 line.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252IH2-3.png "title =" 134.png"/>


Then add the colorThemeId parameter to line 3552-2558.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252K235-4.png "title =" 135.png"/>


Next, add the minifierType parameter.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252K332-5.png "title =" 136.png"/>

As you can see from the above, to set minifierType = css, there must be two conditions. 1 is the uri ending with css and jsp, and 2 is the themeCssFastLoad must be enabled.However, setting minifierType = js must enable themeJsFastLoad.


Because in our example, our request finally includes css_fast_load = 1, so themeDisplay. isThemeCssFastLoad is true, so our request parameter is added with minifierType = css.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252J1H-6.png "title =" 137.png"/>


Fail. fast. load default value false) or css_fast_load = 0, then the themeDisplay. isThemeCssFastLoad is false. The request will not contain minifierType = css.


Next, the parameter languageId is added to the line 3594-3597.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252HE5-7.png "title =" 138.png"/>


Add the build number parameter to the 3599-3602 line:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252K940-8.png "title =" 139.png"/>


The timestamp parameter is added to 3604-3620:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252M145-9.png "title =" 140.png"/>


Therefore, these parameters are spliced after the original access to platform-In-theme/css/main.css, forming the final access url.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252HF3-10.png "title =" 141.png"/>


Of course, the main focus of our article is cssfast load, minifyType,

So we can see:

A. When the request url contains css_fast_load = 1, this request parameter has minifierType = css, which is also consistent with the one shown on the page and tested on another machine ):

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252HM4-11.png "title =" 142.png"/>

B. When css_fast_load = 0 in the request url or this parameter is not available, the request parameter does not contain minifierType = css.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252I5c-12.png "title =" 143.png"/>


All of these occur before the MinifyFilter filter .. Next, let's see how this parameter affects the MinifyFilter.


No matter what the following parameters are, this request is actually a css request. Because our request is/platform-In-theme/css/main.css, it matches the url pattern of the Minifier Filter.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252L322-13.png "title =" 145.png"/>


Therefore, the MinifierFilter processFilter method is used. This method then calls the getMinifiedContent () method:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252GL1-14.png "title =" 146.png"/>

Here we can see that it reads the minifierType parameter in the 284th line, because we use css_fast_load = 1 in our example, so the minifierType string here is "css ", if the css_fast_load = 1 parameter is not set, the minifierType string is null.


Row 3 shows that if the minifierType is empty, skip the execution of the getMinifiedContent method. Because our minifierType is not empty, we will continue and continue until 348th rows,

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11252I5B-15.png "title =" 149.png"/>

It determines that if the resource file is a css extension, the minifyCss method is called. This method combines multiple css files, removes section spaces, and uses yui-compressor to compress and merge. The details of this method can be described in the following article.


It can be summarized at least that if css_fast_load is 1, The minifyCss method will be called. If css_fast_load is 0, the minifyCss method will not be called at all.



Summary:

From the above debugging, we can at least draw the following conclusions:

(1) Before entering the MinifyFilter filter, the Liferay framework will append several parameters to each resource request. The required parameters include: browserId, themeId, languageId, build number, timestamp.

Setting. fast. load = true, the parameter minifyType = css will be appended. If the request is css_fast_load1_0133 and you use the theme.css. fast. load configuration in the corresponding portal.properties, this parameter minifyType will not be appended. js resources are also.

(3) When a css resource is requested, it enters the Minifier Filter, which checks the minifyType = css | js parameter. If this parameter is set, for example, minifyType = css, it will call the minifyCss method to merge multiple css values. If this minifyType is not set, the execution of this method is skipped, that is, the Mini operation is not performed.




This article from "parallel line cohesion" blog, please be sure to keep this source http://supercharles888.blog.51cto.com/609344/1284078

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.