The StackPath Toolkit provides the necessary elements to dynamically integrate StackPath with MODX. There are five elements to the toolkit:
The following pre-requisites are required prior to installation:
On installation of the StackPath component, have the following pieces of information available to expedite the setup:
Note: It is recommended that you initially select the disabled option on install otherwise the StackPath Linker plugin will be immediately active which may not be desired. Once the component is installed, you can check settings, make any configuration or rule changes and then enable the StackPath integration.
For the purpose of documentation or if you do not select the 'Install Default Rules' option on install and later decide you want to use them, here are the default rules shipped with the StackPath Toolkit:
1. Site URL src and href links
Replace src and href links that start with the site URL.
((?:<(?:a|link|img|script)\b)(?:[^>]+)(?:href|src)=")(?:{site_url})([^>]+\.(?:jpe?g|png|gif|svg|xml|js|css)")
{match1}{cdn_url}{match2}
2. Base URL src and href links
Replace src and href links that start with the base URL.
((?:<(?:a|link|img|script)\b)(?:[^>]+)(?:href|src)=")(?:{base_url})([^/][^>]+\.(?:jpe?g|png|gif|svg|xml|js|css)")
{match1}{cdn_url}{match2}
3. Relative URL src and href links
Replace relative src and href links.
((?:<(?:a|link|img|script)\b)(?:[^>]+)(?:href|src)=")(?!(?:https?|/))([^>]+\.(?:jpe?g|png|gif|svg|xml|js|css)")
{match1}{cdn_url}{match2}
If you want to cache web fonts via StackPath, you can add the extensions to the default rules above but please enable the 'Add CORS Header' option for the StackPath site in their control panel.
When adding a rule, you can select the scheme to use for the CDN URL from one of the following: HTTP, HTTPS, or Schemeless.
When installing StackPath and selecting to install the default rules is to have the rules use HTTPS (because all default StackPath already have shared SSL enabled). You really should make use of this option unless you have a specific need to stick with HTTP. Remember, if using a custom domain, you must upload a valid SSL Certificate/Key to the site using their control panel to be able to use HTTPS.