{{…}}
or <%…%>
) outside the text content of elements (tags) and attribute values, which allows minimizing it as regular HTML.HtmlMinificationSettings
class:Property | Data type | Default value | Description |
---|---|---|---|
ProcessableScriptTypeList | Line | Empty line | Contains a comma-separated list of script tag types (for example, text/html,text/ng-template ), the contents of which must be processed by the HTML minimizer. |
MinifyKnockoutBindingExpressions | Boolean | false | The flag responsible for minimizing the Knockout bindings in the data-bind attributes and containerless comments. |
MinifyAngularBindingExpressions | Boolean | false | The flag responsible for minimizing Angular binding expressions in Mustache-like tags ( {{ }} ) and directives. |
CustomAngularDirectiveList | Line | Empty line | Contains a comma-separated list of custom Angular directives (for example, myDir,btfCarousel ) that contain binding expressions. If the value of the MinifyAngularBindingExpressions property is true , then the expressions in the user directives will be minimized. |
script
tags that do not contain JavaScript code were simply ignored by the HTML minimizer. This was done because these tags can contain anything from VBScript code to Handlebars templates. But at the same time, if the script
tag contains the code of the DOM template, then it would be worth letting it through the HTML minimizer. Therefore, users were given the opportunity to determine the list of acceptable content types themselves.ProcessableScriptTypeList
property ProcessableScriptTypeList
be set to a value equal to text/html
.text/ng-template
.text/html,text/ng-template
.text/x-kendo-tmpl
content type for Kendo MVVM views, which differ little from Knockout ).shell.html
file from the demo project HotTowel : <div> <header> <!--ko compose: {view: 'nav'} --><!--/ko--> </header> <section id="content" class="main container-fluid"> <!--ko compose: {model: router.activeItem, afterCompose: router.afterCompose, transition: 'entrance'} --> <!--/ko--> </section> <footer> <!--ko compose: {view: 'footer'} --><!--/ko--> </footer> </div>
<div><header><!--ko compose: {view: 'nav'}--><!--/ko--></header><section id="content" class="main container-fluid"><!--ko compose: {model: router.activeItem, afterCompose: router.afterCompose, transition: 'entrance'}--> <!--/ko--></section><footer><!--ko compose: {view: 'footer'}--><!--/ko--></footer></div>
compose: {view: 'nav'}
, which, in its essence, is an object in JSON format without external curly braces. We can wrap it in braces: {compose: {view: 'nav'}}
, and process it with a JS minimizer. Then remove the external curly brackets from the minimized code and return it to containerless comment.MinifyKnockoutBindingExpressions
property MinifyKnockoutBindingExpressions
set to true
, then all the actions described above will be applied to the expressions. For these purposes, CrockfordJsMinifier
is always used as a JS minimizer, because only it can correctly minimize JSON code ( MsAjaxJsMinifier
and YuiJsMinifier
not suitable for this purpose). <div><header><!--ko compose:{view:'nav'}--><!--/ko--></header><section id="content" class="main container-fluid"><!--ko compose:{model:router.activeItem,afterCompose:router.afterCompose,transition:'entrance'}--> <!--/ko--></section><footer><!--ko compose:{view:'footer'}--><!--/ko--></footer></div>
data-bind
attributes. For example, we have the following code: <span data-bind="text: price() > 50 ? 'expensive' : 'cheap'"></span>
<span data-bind="text:price()>50?'expensive':'cheap'"></span>
CrockfordJsMinifier
. The only problem was only one-time binding expressions (starting with ::
. The original JSMin always removed the whitespace before it, but after making small changes to the CrockfordJsMinifier
code, the problem was fixed.{{ }}
) and directives. <strong>Price:</strong> {{ 3 * 10 | currency }}
<img src="/Content/images/icons/{{ iconName + '.png' }}">
MinifyAngularBindingExpressions
property MinifyAngularBindingExpressions
set to true
, then we will get the following results: <strong>Price:</strong> {{3*10|currency}}
and <img src="/Content/images/icons/{{iconName+'.png'}}">
class
attributesngBind
directive there are the following options:ng-bind
ng:bind
ng_bind
x-ng-bind
data-ng-bind
ngController
, ngCopy
, ngCut
, ngDblclick
, ngDisabled
, ngFocus
, ngHide
, ngIf
ngInit
, ngKeydown
, ngKeypress
, ngKeyup
, ngModelOptions
, ngMousedown
, ngMouseenter
, ngMouseleave
, ngMousemove
ngPluralize
. More specifically, expressions in the count
and when
attributes are minimized. <ng-pluralize count=" personCount " when="{ '0': 'Nobody is viewing.', 'one': '1 person is viewing.', 'other': '{} people are viewing.' }"> </ng-pluralize>
<ng-pluralize count="personCount" when="{'0':'Nobody is viewing.','one':'1 person is viewing.','other':'{} people are viewing.'}"> </ng-pluralize>
data-bind
attributes in Knockout, because here you don’t need to think about external curly braces.ngRepeat
directive as an ngRepeat
: <li ng-repeat="customer in customers | filter:nameText | orderBy:'name'"> {{customer.name}} - {{customer.city}} </li>
<li ng-repeat="customer in customers|filter:nameText|orderBy:'name'">{{customer.name}} - {{customer.city}}</li>
class
attribute can contain several directives at once: <span class="ng-bind: name; ng-cloak; ng-style: { 'background-color': 'lime' };"></span>
<span class="ng-bind:name;ng-cloak;ng-style:{'background-color':'lime'}"></span>
myDir
will be used as a comment directive: <!-- directive: my-dir 1 + 1 -->
<!--directive:my-dir 1+1-->
CustomAngularDirectiveList
property will be processed by the minimizer as well as built-in Angular directives.Source: https://habr.com/ru/post/239025/
All Articles