Defining Rules

(Pro Version only)


HTML Shrinker Pro offer the possibility to define your own shrinking rules in the Rules tab of the Options dialog. These self-defined rules can be used to remove special tags, expressions or code parts, to replace special expressions or to make HTML Shrinker Pro ignore certain parts of the code during the shrinking process. As you might guess Rules are a powerful tool for creating your own shrinking options and thereby extending HTML Shrinker's built-in shrinking capabilities.

Beside these user-defined rules there are a few rules already built into HTML Shrinker (Remove Images, Remove Scripts, Remove Styles, Remove NB Spaces etc.). For more information on them, please read the Cleaning page.

 

Open / Save

Displays a file dialog for opening or saving a rule file. These rule files have the file extension .rul and can contain several rules. Opening a rule file will add the rules that are contianed in the file to the rule list at the left side. Saving a rule file will save all rules that are currently displayed in the rule list into the rule file.

Add / Edit

Lets you add a new user defined rule or edit an existing rule. The following dialog appear when Add or Edit is pressed:

Name:

For entering the name of your rule.

Rule:

Lets you select between different rule types.

A: / B:

Lets you enter text for the rule expressions A and B.

Case Sensitive:

Is only aavilable for the last four rule types. Lets you define if the text entered in A and B should be considered case sensitive. If this check box is deactivated the rule does case insensitive searches.

Place:

Is only active for the last four rule types. Lets you define if HTML Shrinker Pro should search for the expressions entered in A and B "Everywhere", "Only Inside Tags" or "Only Outside Tags".

 

The "Arrow Up" and "Arrow Down" buttons

Lets you move the currently selected rule one position up or down in the rule list. The first activated item in the rule list is perfomed before the second activated one and so forth. So you can use these buttons to change the order of execution of the rules.

Deselect All

Deactivates the check boxes of all activated rules.

Delete

Deletes the selected rule. Please notice that it is easier to deactivate the check box of the appropriate rule if you don't want that it will be applied. Only if the rule won't be of any use anymore, you should delete it.

 

Using the Shrink, Shrink All, Shrink Clipboard or Simulate Shrinking, Analyse, Analyse All commands will perform the activated rules. If one or more of the check boxes in the Rules tab are activated, there will be a notice in the Activated Rules field of the main window.

 

Examples

For examples of what can be achieved with self-defined rules please have a look at the rules that already come with HTML Shrinker Pro. Nevertheless are some examples that will illustrate how to define your own rules:


1. To remove all META tags, select "Remove all <A> tags" from the Rule combo box and enter meta in the A text box. This setting will remove all tags beginning with <meta or <Meta or <META or <mETA or <MetA etc. and ending with >.


2. To remove all CENTER and /CENTER tags, select "Remove all <A> and </A> tags" from the Rule combo box and enter center in the A text box. This setting will remove all tags beginning with <center or <Center or <Center or <cENTER or <CenteR etc. and ending with > as well as remove all </center> or </Center> or </Center> or </cENTER> or </CenteR> etc. tags.


3. To remove all links including the linked text, select "Remove everything between <A> and </A> tags" from the Rule combo box and enter a in the A text box. This setting will remove all code beginning with <a{space} or <A{space} and ending with </a> including the tags itself.


4. To remove all forms, select "Remove everything between <A> and </A> tags" from the Rule combo box and enter form in the A text box. This setting will remove all code beginning with <form or <Form or <FORM or <forM etc. and ending with </form> or </Form> or </FORM> or </forM> etc. including the tags itself.


5. To remove the expression "target=_blank", select "Remove A" from the Rule combo box, enter target=_blank in the A text box and select "Only Inside Tags" from the Place combo box. This setting will remove all target=_blank or TARGET=_blank etc. expressions.

If you activated the Case Sensitive check box, only the target=_blank expression will be removed. The TARGET=_blank or TARGET=_BLANK etc. expressions wouldn't have been removed.


6. To remove all PHP code, select "Remove everything between A and B" from the Rule combo box, enter <?php in the A text box, enter ?> in the B text box and select "Everywhere" from the Place combo box. This setting will remove all code beginning with <?php and ending with ?>.


7. To replace the word "Harold" with "Harry", select "Replace A with B" from the Rule combo box, enter Harold in the A text box, enter Harry in the B text box, activate the Case Sensitive check box and select "Only Outside Tags " from the Place combo box. This setting will replace all occurances of Harold outside tags with Harry.


8. To keep HTML Shrinker Pro from shrinking the html body, select "Ignore everything between A and B" from the Rule combo box, enter <body in the A text box, enter </body> in the B text box, deactivate the Case Sensitive check box and select "Everywhere" from the Place combo box. This setting will keep HTML Shrinker Pro from doing any changes to the html body.


These are just some examples of what can be done with self-defined rules. There are a lot more possibilities to create rules customized to your needs.

 

Possible Problems with Interfering Rules

If you activated more than one rule in the rule list, it is possible that two or more rules interfer with each other and don't produce the effect you intended. The reason for potential problems could lay in the fact that the rules are excuted in the order in which they are displayed on the rule list.

For example if the "Ignore Header" rule is below the "Remove Scripts" in the rule list, scripts will nevertheless be removed from the header. To make sure that no script is removed from the header of a html file, you have move the "Ignore Header" rule above the "Remove Script" rule with the Arrow-Up-button. Generally make sure that all activated rules of the Ignore-type are placed above all activated Remove-type rules.

It could also be that one of the later executed rules causes a problem with a previuos performed rule. This is because the first rule isn't performed on the whole html file before the second rule is started. Merely all rules are performed simultaneously e.g. on the same tag one after the other.

For example when you activate the "Remove All Tags" rule and have a rule which uses "Only Outside Tags" for the Place operator, the second mentioned rule won't work. The reason for this is that the "Remove All Tags" rule removes all tags which causes the "Only Outside Tags" operator of the other rule to fail. To solve this problem you could change the Place operator of the one rule to "Everywhere". If this isn't possible, you would have to shrink the html file two times, each time with a different rule activated.

 


TIP: If you think your self-defined rules would be useful for other people, too, please save them as a .rul file and send them to us. We can then include them with the next version of HTML Shrinker.

TIP 2: If you should have deleted one or more of the rules that are included with HTML Shrinker, there's no problem to restore them. Just press the Open button in the Rules tab and select "Default.rul" from the HTML Shrinker Pro folder.

 

Back to Main