Well done! You’ve started publishing your site on Strattic!
Publishing is already very fast on Strattic (thanks devs!), but what if you have a massive site or just want to speed up your publishes and have even more control over what gets published?
Good news – you can exclude specific paths or patterns of paths to exclude from your publish!
Here, we’ll show you how to inspect which paths/URLs from your site are getting published and different ways to optimize that list. Jump to a section below:
- Inspecting Strattic’s detected paths/URLs for your site
- The no-code cleanup approach
- Strattic’s Publish Settings within WordPress
- WordPress plugins to combine assets
- Apply Strattic’s WordPress filters to control what gets published
Inspecting Strattic’s detected paths/URLs for your site
There’s a handy URL within your Strattic site for checking our detected paths from your site – those which our system will try to publish.
https://{YOURSITE}.site.strattic.io/strattic-api-request?json_debug=1
Just in case you’re not a JSON fan, we also provide a text-only endpoint at:
https://{YOURSITE}.site.strattic.io/strattic-urls
These endpoints will have some other information, such as total post/page/path count and some other meta information more useful for our system than to you. The main thing you’ll want to focus on here is the paths
property in the JSON response.
Don’t like loading big JSON files in your browser? I hear you! When looking at a site’s paths, I like to download a local copy of either the original JSON paths or turn that into a flat file containing only the paths.
Downloading a copy of your Strattic detected paths
Note, that as your site is kept non-public via HTTP Basic Authentication, when requesting these URLs outside of an authenticated browser session, you’ll need to include your HTTP Basic Auth user and password, which you can find in your Strattic dashboard:
Download Strattic’s detected paths as JSON
curl -s "https://{USER}:{PASS}@{YOURSITE}.site.strattic.io/strattic-api-request?json_debug=1" | jq .paths > strattic-detected-paths.json
Example output:
[
{
"path": "/",
"priority": 6,
"quick_publish": true
},
{
"path": "/404.html",
"priority": 8,
"quick_publish": true
},
{
"path": "/robots.txt",
"priority": 5,
"quick_publish": true
},
(Don’t worry about the priority
and quick_publish
properties for now, we set good defaults for them, so you can focus on just the path
property)
Download Strattic’s detected paths as flat file containing a path on each line
curl -s "https://{USER}:{PASS}@{YOURSITE}.site.strattic.io/strattic-api-request?json_debug=1" | jq .paths | jq .. | jq .path | sort | sed 's/"//g' > strattic-detected-paths.txt
Example output:
/
/1/
/2/
/3/
/4/
/404.html
/author/someauthor/
/category/documentation/
/comments/feed/
/contact/
/sitemap.xml
/favicon.ico
/feed/
/page-sitemap.xml
/page/1/
/page/2/
OK, now you know where to inspect the paths Strattic has detected as publish-worthy for your site!
Read a bit further to see different ways to trim this list of paths down.
The no-code cleanup approach
On old, non-static WP hosting, non-essential files like my-active-theme/style-version2-OLD.css
don’t cause too many problems (security issues, aside!). If a user doesn’t explicitly request that path, it won’t get served.
On Strattic, because we publish files that logically look required for your site, we’d publish such an unnecessary file, as it would meet such rules as:
- active child/theme directory
- valid frontend asset extension
We have some smarts to auto-exclude things like non-active parent/child themes, inactive plugins, PHP files and more. Whilst we continually improve these rules, if you can remove such unnecessary backup files/folders from your site, that will benefit in multiple ways:
- reduce your publish times
- speed up your backup/restore times
- declutter your filesystem
It’s definitely worth making sure there’s nothing in your site that’s not necessary for the site’s functionality. If worried about keeping backup copies of files, using a version control system such as Git, will offer a much more robust and efficient workflow. Please reach out if you’d like some advice on adopting such practices.
Strattic’s Publish Settings within WordPress
This is also a no-code, low-barrier way to adjust the paths we detect for your path.
Within WordPress Dashbord > Strattic > Settings > Advanced, you’ll find we’ve given users control over common types of excludable paths. We set useful defaults, but you can check these to see if there’s anything more there you can 1-click exclude by un-checking the box.
You can access this URL within your site to reach the same page:
/wp-admin/admin.php?page=strattic-settings&tab=advanced
Currently, the togglable options are:
- Attachment pages
- RSS
- RDF and Atom Feeds
- Shortlinks
- Date archives
- Enabled
- Additional non-essential URLs
Read more about each of these options
WordPress plugins to combine assets
This technique may be determined by your preference for asset loading in regards to on-page performance optimisations, but worth trying out.
Plugins like Autoptimize can do some really neat things to reduce the number of assets your published site needs:
- inline scripts to not require loading that asset’s file at all
- aggregate scripts loaded on a page, to turn 10 requests into 1 (and 10 files into 1!)
- optimize fonts to load with fewer requests
You can find many similar plugins and some page builders also include similar functions for on-page optimization, which can speed up your Strattic publishes by requiring fewer paths to be detected and published.
Apply Strattic’s WordPress filters to control what gets published
We love to empower developers like you working on Strattic sites, so we try to build in extensibility in the form of WordPress hooks and filters for you to use. These can help you have more control over the way your static site is published and allow you to build useful integrations!
For fine-grained control over the paths Strattic will publish for your site, you can use one or more of these WordPress filters:
strattic_paths
This is the filter called at the end of our path detection process and the following would print out all of the paths which would render in the /strattic-api-request
URL introduced at the start of this doc:
<?php
// Print out all detected paths from your site without modifying them.
add_filter(
'strattic_paths',
function ( $detected_paths ) {
error_log( print_r( $detected_paths, TRUE ) );
return $detected_paths;
}
);
This and all example code blocks here could be placed within your theme’s functions.php
or added to a custom plugin.
Let’s enable WP_DEBUG and logging to file in order to inspect the detected paths we’re logging above:
// wp-config.php
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
Now, if we make a request to /strattic-api-request
, we should see similar to this in your wp-content/debug.log
file:
[29-Aug-2022 11:14:19 UTC] Array
(
[0] => Array
(
[path] => /
[priority] => 8
[quick_publish] => 1
)
[1] => Array
(
[path] => /404.html
[priority] => 8
[quick_publish] => 1
)
[2] => Array
(
[path] => /robots.txt
[priority] => 5
[quick_publish] => 1
)
[3] => Array
(
[path] => /favicon.ico
[priority] => 5
[quick_publish] =>
)
[4] => Array
(
[path] => /sitemap.xml
[priority] => 5
[quick_publish] => 1
)
.... (truncated output for example)
That gives us an idea of the structure within the array that strattic_paths
filter gives us.
Let’s suppose for some reason, you wanted to to exclude the favicon.ico
from being published in your static site, we could add a function like this:
// Exclude a specific detected path from being published.
add_filter(
'strattic_paths',
function( $detected_paths ) {
$key = array_search(
'/favicon.ico',
array_column( $detected_paths, 'path' ) );
unset( $detected_paths[ $key ] );
error_log( print_r( $detected_paths, TRUE ) );
return $detected_paths;
}
);
And now, our log should show the favicon.ico
excluded from our list of paths we’re going to publish:
[29-Aug-2022 11:31:15 UTC] Array
(
[0] => Array
(
[path] => /
[priority] => 8
[quick_publish] => 1
)
[1] => Array
(
[path] => /404.html
[priority] => 8
[quick_publish] => 1
)
[2] => Array
(
[path] => /robots.txt
[priority] => 5
[quick_publish] => 1
)
[4] => Array
(
[path] => /sitemap.xml
[priority] => 5
[quick_publish] => 1
)
.... (truncated output for example)
Great! We’ve seen a pretty simple way to work with strattic_paths
, which contains the whole list of detected paths. But, we want everything to be fast, so if we can, let’s avoid iterating the whole list of paths and use the more specific filters below when possible!
Excluding paths detected via filesystem scanning
Our path detection system is pretty cool – it uses multiple techniques to best detect the required paths for your site. These techniques includes things like using WordPress core + plugin APIs, querying the database and scanning the filesystem for relevant files.
The filesystem scanning is a great way to detect static assets (fonts, CSS, images, etc) which WordPress doesn’t have a programmatic way to access. We err on the side of detecting too much than not enough, so that your site doesn’t miss needed assets.
An example use case where you may want to trim this down would be a plugin directory, which your site only needs some assets from, but contains way too many. ie, there may be one JS or CSS file that gets loaded from that plugin directory, but it also contains a lot of JS/CSS used within the WordPress dashboard settings for that plugin – we definitely don’t need to be publishing those WP dashboard assets for your site to function, so they’re a good candidate to specifically exclude!
/wp-content/plugins/someplugin/wp-dashboard/style.css <-- don't want this!
/wp-content/plugins/someplugin/frontend/style.css <-- want this!
With over 60,000 WP plugins in the world, we can’t safely exclude all wp-dashboard
directories within plugins, due to:
- not every plugin author structures their plugins the same way
- some plugins may load your site’s frontend assets from such directories
You can see the challenge! That’s why we give you control over your path exclusions – you’ll know your site best and can choose what to exclude!
strattic_directory_exclusion_matches
This is a great filter to exclude specific directories you know you don’t need, like the wp-content/plugins/someplugin/wp-dashboard
example above.
<?php
// Exclude exact directory matches from filesystem scan.
add_filter(
'strattic_directory_exclusion_matches',
function( $detected_directories ) {
// Exact match directories we want to add exclusion rules for.
$exact_match_directories = [
WP_CONTENT_DIR . '/plugins/someplugin/wp-dashboard',
];
// Return modified exclusions (array_flip to use values as keys)
return array_merge( $detected_directories, array_flip($exact_match_directories));
}
);
Why not just use the strattic_paths
filter we learned earlier? You totally could, but the advantage of this filter, is that it runs before adding all the paths to where the strattic_paths
filter runs. It’s also specifically a directory excluder, so as soon as our system hits this directory, it will skip it. If relying on strattic_paths
filter, we’d need to traverse the whole directory, which could be thousands of paths, add them all the main path list, then iterate that whole list to filter out all matching paths – a lot more processing time and memory would get used in that scenario and we want things to be efficient!
Because these filesystem exclusion filters run before the strattic_paths
filter, that’s still a good filter to debug these exclusions have been applied correctly, else hit that JSON endpoint at /strattic-api-request
.
You’ll also note in the example function above, we use the WP constant WP_CONTENT_DIR
when building our paths to exclude. This is a safer way to get the correct directory, in case you’ve overriden the usual wp-content
directory (some users do this to make their site look less WordPress-y to tools like builtwith.com).
strattic_directory_exclusion_patterns
Similar to the above filter, this gets applied to all directories we’re scanning in your site’s filesystem.
The difference with this filter, is hinted in its last word, patterns. Where strattic_directory_exclusion_matches
matches exact directory paths, strattic_directory_exclusion_patterns
allows you to use regular expressions (regex) patterns to match directories you want to exclude from detection/publishing.
We use such a pattern behind the scenes to exclude all admin
directories within a plugin directory. We’ve found this to work well at excluding a lot of plugin admin
directories without issues, but in case you do encounter such an admin
directory required for your site’s frontend, you can use this filter to remove that exclusion rule from the list.
Here’s the PHP regex pattern we use with this filter:
'~^' . preg_quote( WP_PLUGIN_DIR, '~' ) . '\/.\/admin\/.~i'
And here’s an example of how you could use a pattern with this filter to exclude any directories within your wp-content
directory, whose path starts with PDFs
or pdfs
and a nested 2020
directory (a year we’d love to forget!).
Detected paths before applying this filter:
/wp-content/PDFs/retail/2020/a.pdf
/wp-content/PDFs/retail/2020/01/b.pdf
/wp-content/PDFs/wholesale/2021/c.pdf
/wp-content/pdfs/retail/2020/e.pdf
/wp-content/pdfs/retail/2021/f.pdf
The filter:
// Exclude directories matching patterns from filesystem scan.
add_filter(
'strattic_directory_exclusion_patterns',
function( $directory_exclusion_patterns ) {
// Exact match directories we want to add exclusion rules for.
$directory_exclusion_patterns[] =
'~^' . preg_quote( WP_CONTENT_DIR, '~' ) . '\/PDFs\/.*\/2020\/.*~i';
// Return modified directory exclusion patterns
return $directory_exclusion_patterns;
}
);
Detected paths after applying this filter:
/wp-content/PDFs/wholesale/2021/c.pdf
/wp-content/pdfs/retail/2021/f.pdf
Regular expression patterns allow for some great control over your exclusions, as shown above.
Excluding paths from the WordPress uploads directory
Before you go writing the most amazing exclusion regex for a bunch of things you don’t want detected from your wp-content/uploads
directory, please be aware, that we by default handle the detection and publishing of any directories beginning with a 4-digit year within your uploads directory, ie wp-content/uploads/2022/01/01
, using a different process. This generally speeds up media file publishing for large sites, but if you’d like us to disable that for your site, so you can control the detection/publishing of those directories, please reach out to us via Strattic Support.
strattic_file_path_exclusion_patterns
This filter can be used similarily to the strattic_directory_exclusion_patterns
one above, but will apply exclusions to files, not directories.
strattic_file_path_basename_exclusion_matches
We use this filter behind the scenes to efficiently exclude unnecessary filenames, ie operating system files which can get inadvertantly added to your site during development. Or files often included in plugins or themes by developers, but not necessary for site functionality.
Examples we use this to exclude, which you can extend by applying the filter:
.DS_Store
.tmp
thumbs.db
__MACOSX
.editorconfig
README
Adding to this filter will exclude all files with matching basenames (case insensitive).
Other useful filters for excluding paths
And some other filters which may be useful for particular cases. We’ll continue to update this documentation with more example code, but in the meantime, you may use the same technique as above to debug what kind of array data the filter provides and modify it according to your needs.
Exclude particular post statuses from being published:
strattic_post_statuses
Exclude particular post statuses from being published:
strattic_post_types
Celebrating national no-GIF day? Exclude all .gif
‘s from publishing:strattic_extensions
Got too many sitemaps coming from your SEO plugin and want to exclude or modify them? There’s a filter for that!
strattic_add_sitemap_paths
Apply exclusions only to Selective Publishes:
strattic_paths_selective
Safety first!
While refining your path exclusions, please be sure to use the WP_DEBUG log or other method to debug and get confidence of the paths you’re going to export. Use your Strattic site’s Preview enviroment to publish to first and make sure there’s no accidental exclusion of paths needed for your site.
If in doubt, please reach out – Strattic support.