By default, the StackPath CDN only caches specific file types, but it is possible to use StackPath EdgeRules to cache other types as well.
This can be very helpful for distributing certain video formats, or a Single Page Application (SPA) that requires other file types to function.
This article assumes a StackPath CDN Site has already been created.
Creating the Rule
After logging into the StackPath Control Portal, open a CDN site and select the EdgeRules tab. From here, please select Add Custom Rule, near the bottom of the page. You'll then be presented with the Add Custom Rule dialog.
EdgeRules must have the following:
- Name - The name of the Rule to allow you to identify it in your CDN configuration
- Conditions - Defines the conditions under which your rule will be enforced. It's possible to configure multiple statements for a single rule via the use of AND, however, you can only configure one IF per type, and the rule will only trigger if all conditions are met.
- Rules - Defines what will happen when your rule is enforced.
To enable caching for a specific file type you can create a very simple condition to define that a URL matching a wildcard has the response cached for one hour, which can be seen in the screenshot below. As you can see the URL must match
*.ts for the file to be cached for 3600 seconds(1 hour).
Of course, you're not limited to just .ts files and you could use any file extension you need and you can also cache these files for as long as you want. Once you're happy with the rule, simply click save and it the CDN will immediately begin caching .ts files.
It's also possible to create more complex rules according to the EdgeRules URL Filters documentation. For instance, if you wish to cache both .ts and .webm files you may wish to update your URL pattern to
*.ts,*.webm, which can be expanded to include further filetypes if required.
If you come across any questions, or have any concerns, feel free to reach out to StackPath's 24/7 support team, we'll be happy to help!