What is Rule-Based Injection?
By default, RapidLoad queues and optimizes each URL separately. While this is perfectly fine for smaller websites and necessary on custom pages, it can take quite a long time to discover and optimize every page on a larger website. It may even be redundant on sites that serve multiple pages using the same template (or set of templates) with multiple shared CSS files.
With Rule-Based Injection, you can now supply RapidLoad rules to discover and optimize multiple shared CSS files simultaneously. Optimized files are then applied to matching pages at the same time, significantly reducing the time to reach full site optimization.
Who Should Use Rule-Based Injection?
Anyone! However, users with large websites will see the biggest benefit in time saved.
How To Enable Rule-Based Injection
- Ensure you are using the latest version of the RapidLoad Wordpress plugin. Rule-Based Injection is available in versions 1.4.11+. Update the plugin if necessary.
- Navigate to Advanced Settings and check the box labeled “Enable rule based injection”
- Click the “Save Changes” button at the bottom of the page. Once your changes have been saved, a new “Rules” section will appear below the Optimizations table.
How To Structure Injection Rules
WARNING: We strongly recommend users read and understand this section before adding and applying rules. Rules can introduce breaking changes if not configured correctly. If you have any additional questions about how rules function, please don’t hesitate to reach out to support for help.
There are elements required to set up a rule: the rule type, a base URL, and URL pattern.
Rule Type
Choose from a list of available content types to target, including taxonomies and custom post types.
Base URL
The Base URL serves two roles:
- It is the page RapidLoad crawls for CSS files
- It defines the top level that RapidLoad starts from when looking for additional pages to apply the optimized CSS.
For example, with the Base URL in a rule set to https://www.example.com/category1/
, RapidLoad would optimize the CSS files on https://www.example.com/category1/
. When looking for additional pages to apply the optimized CSS, RapidLoad would only be permitted to look through pages below https://www.example.com/category1/
, such as:
https://www.example.com/category1/product1/ |
https://www.example.com/category1/product2/ |
https://www.example.com/category1/product2/page1 |
https://www.example.com/category1/product3/page1/subpage1 |
A pattern is then used to further restrict which pages the new CSS is applied to.
Pattern
To further restrict which pages match your rule, you must enter a Pattern. The Pattern input accepts both relative and absolute paths, as well as glob characters and complex regular expressions.
Examples:
Type: Base URL: Pattern: Matches:
|
Type: Base URL: Pattern: Matches:
|
How To Add A Rule
- Click the +ADD button on the “Rules” table to open the new rule modal.
- Select the Type from the dropdown menu. Manually enter the Base URL and Pattern.
- Click Update Rule. A Job will be added to the queue and listed in the Rules table.