Getting Started
Choose the right plan
Swift Performance is the best choice to speed up your WordPress sites. There are 4 + 1 available plans:
Single plan
You can use Swift Performance with Single plan for 1 WordPress site. It can be the right choice if you have only 1 site, or if you would like to test what can Swift Performance do (you can upgrade your subscription later).
Multi plan
You can use Swift Performance with Multi plan for up to 5 WordPress sites. Regarding that the Multi plan price is very reasonable, if you have at least 2 sites you should choose Multi plan.
Developer plan
As the plan name suggest this plan is the best for developers, who manage many sites. You can use Developer Plan for up to 30 WordPress sites. If you are an agency, or freelancer, who has few clients you should choose Developer plan.
Business plan
We created Business plan for professional speed up experts, who doesn't manage the site, but speed up WordPress sites as a service. Business plan can be used on unlimited sites. For this plan monthly subscription is also available, so you can choose the monthly plan with a reasonable monthly fee as well.
Micro plan
Micro license is a special Single license for bloggers and personal sites. Even if your project generates some income you can use Micro license if your project meets the following requirements: Your site may can generate income from ads, but you can't sell any service/product (including PR articles) on the site. Using Micro license is not allowed for politically active sites.
Install Swift Performance
- Login to My account on musthaveplugins.com
- On the next screen you will see your subscriptions. Choose any active subscription and click to Manage Subscription
- On the next screen click to Download in Swift Performance section
- Login to WordPress admin where you would like to install Swift Performance
- Go to Plugins > Add new and click to upload plugin
- Select the previously downloaded ZIP file and click to install
- Now let Swift Performance to configurate itself
Basic configuration
Caching
Caching is one of the core functions of Swift Performance. The cache warmer will load all of your pages - when necessary - and save a static version of every pages.
Once a visitor will be served from cache, your server will load this static file, which need much less resources (CPU and memory) and of course it is much faster than generate the page for every visit.
Some managed hosting has their own caching system (which sometimes even faster, but mostly it is better only for the hosting company), so you can disable caching in Swift Performance.
Otherwise - in the most cases - you should let caching enabled in Swift Performance.
Optimize CSS
CSS optimization can improve Core Web Vital, it should be always enabled. There are 3 levels of optimization:
- Disabled
- Generate Critical CSS and optimize CSS delivery
- Optimize font delivery
If there are no issues with your fonts, then you should always set it to full optimization
Optimize JS
One of the best improvements in Swift Performance is the real javascript optimization. If this feature is enabled Swift Performance will optimize javascript execution and decrease the load on main browser thread. It can speed up your site even for logged in users and on non-cached pages.
JS Delivery
Swift Performance can also improve the javascript delivery. It means Swift Performance will manage which script should be loaded and when. There are 3 levels of JS delivery feature:
- Disabled
- Offload main thread
- Delay less important scripts
If there are no issues on the site you should set it to maximum level, however in rare cases it can cause issues with some themes/plugins. If you have any issues please open a support ticket, and our developer team will check into it. In these cases as a quick fix you can set the level to medium or you can even temporary disable this feature.
Optimize Images
Swift Performance will generate optimized WebP version for all images (including third party and background images) on the fly. Optionally you can also enable Optimize Images on Upload. Swift Performance also can use WebP which has been generated by other plugins, so you can switch instantly.
Optimize Iframes
Swift Performance can create placeholder for iframes, and lazyload them. In that case on the first load only an optimized screenshot will be loaded instead the heavy iframe, and Swift Performance will load the embedded iframe only when it is necessary.
Code Optimizer
Automatically deactivate unnecessary plugins specifically for each respective request using intelligent rules, and apply other small code improvements to speed up WP Admin, AJAX requests and frontend.
Development Mode
Development Mode temporarily suspends caching and optimization features for two hours (unless disabled beforehand).
Advanced configuration
You can tweak advanced settings if you click "Under the hood" button in Configuration. In most cases you won't need to change these settings, except if you need a quick fix until permanent solution from our dev team.
Caching
Logged in cache
If you enable this option Swift Performance will serve cached pages even for logged in users. In most cases you can simply load cached pages for logged in users as well. If there are some parts which should be personalized, you can use fragments to load them AJAX, or enable Collage to automated detection.
Exclude URLs
With this option, you can exclude pages by URL (or URL part). Write one URL (part) per line, then click to update.
Swift Performance will detect non-cacheable pages automatically, however regarding that there are over 50 000 WordPress plugins and approximetly 30 000 themes, it can happen that Swift Performance can't detect a non-cacheable page.
If you find that there is a plugin or theme related page which always should be excluded, please let us know.
Exclude Post Types
With this option, you can exclude post types. You can select multiple post types.
Just like pages, Swift Performance can detect non-cacheable post types automatically as well. However regarding that there are over 50 000 WordPress plugins, it can happen that Swift Performance can't detect a non-cacheable post type.
If you find that there is a custom post type which always should be excluded, please let us know.
Query String
By default Swift Performance will bypass caching if query string is present in the URL. There are 2 options to overwrite this default behavior:
Ignored query parameters
You can define query parameters which should be ignored. Write one parameter per line. Swift Performance ignores some parameters by default:
utm_source, utm_campaign, utm_medium, utm_expid, utm_term, utm_content, fb_action_ids, fb_action_types, fb_source, fbclid, _ga, gclid, age-verified
Allowed query parameters
You can list query parameters which shouldn't be ignored, but should be cached separately. For example if you add "s" parameter, all of your search results pages will be cached separately. Write one parameter per line.
Bypass Cookies
By default Swift Performance will bypass caching if some specific cookies are set. However you can list any cookies here.
If you find that there is a cookie, which always should be bypassed, please let us know.
Enable GZIP
Usually you won't need to enable GZIP manually, because Swift Performance can detect compression and configure it automatically. However if you have double GZIP issues, then you may need to disable this feature in Swift Performance settings.
Browser Cache
With this option you can let Swift Performance to set the expiry headers for different content types. Usually you don't need to disable this, however in some cases (for example if you are using a CDN with own expiry values), it is unnecessary.
Keep Original Headers
Send original headers for cached pages. If you are using a plugin which send custom headers you can keep them for the cached version as well.
Media
Optimize Images on Upload
Swift Performance will optimize all images (even third party, and background images) on demand. This means, when the cache warmer cache a page, it will pick up all images and optimize them on the actual page. Therefore you don't really need to optimize images on upload, however it can be useful if you would like to serve optimized images for the first (uncached) pageview.
Lazyload Images
Swift Performance is using the native lazyload for images, but improve it. Automatically detects important images and exclude them from lazyloading. You need disable this feature only if you would like to use a different plugin for lazyloading (not recommended).
Smart Image Sizing
Swift Performance will automatically resize images for every used viewport size, and will use responsive images on every pages (even for logged in visitors). You need disable this feature only if you would like to use a different plugin for responsive images (not recommended).
Optimize Rendering
Swift Performance will automatically detect the important images on every pages during the optimization process. These images will be excluded from lazyloading and will be preloaded (using the right responsive size) to improve LCP and FCP scores.
Fragments
General
Swift Performance can load some part of the page dynamically and load the rest from cache. You can enable fragment caching for Elementor Widgets or Gutenberg Blocks in the editor, and specify shortcodes which should be loaded dynamically.
Collage
Collage is a smart feature, which identify dynamic part of a page and load them via AJAX. It can be extremly helpful, if you also enable Logged in cache.
Navigation
With this feature Swift Performance will use smart preload technique (based on network bandwidth and device) to speed up the onsite navigation. With preloading important pages before the user navigate the navigation can be nearly instant. It will improve the field data scores, and the user experience as well.
System
On the system tab you can see your subscription status and disconnect the current site from the subscription.
If you need to add the generated rewrite rules manually, you can download them and also can verify that they work.
You can check the API connection status and reconnect API if it is necessary, and you can also start over the whole setup process. Please note if you restart setup, your current settings will be overwritten.
Integrations
General
Swift Performance is compatible with most plugins and themes out of box, however there are a few third-party plugins, themes, server software and services which are highly integrated with Swift Performance. Most of them doesn't need any configuration (like Elementor, Slider Revolution, WP Bakery, LiteSpeed, etc.), some others can be configured - if it is necessary.
Cloudflare
You can enable autopurge Cloudflare cache, which is recommended if you are using Cloudflare APO, or proxy caching. If you previously used any Cloudflare plugin where your API credentials were set, Swift Performance will find them so you don't need to set them again.
If Cloudflare couldn't be configured automatically you need to choose the authentication mode, and enter Cloudflare e-mail and API password, or Cloudflare API token (recommended).
Once you configured Cloudflare you can enable Proxy caching, which will provide the same performance as Cloudflare APO.
Nginx
If your site is running on Nginx server you need to add the generated rules manually to Nginx config.
You can find the rewrite rules on Nginx tab under Integrations, copy the rules, add them to config and restart Nginx.
On Nginx integration tab you can also verify that rules are up-to-date and working.
Varnish
If Swift Performance detects Varnish you can enable Varnish module on Varnish tab under Integrations. Once you enabled it, Swift Performance will manage Varnish cache as well.
WooCommerce
There are some specific features which can be enabled for a WooCommerce site. You can manage them on WooCommerce tab under Integrations.
Prebuild Variations
If you have separate single pages for variations you should also prebuild them. For this you need to enable Prebuild Variations feature, so Swift Performance will automatically preload, cache and optimize available variation single pages for all products.
Checkout Booster
If Checkout Booster is enabled, Swift Performance will preload cart and checkout pages, and force visitors' browser to cache them for a short time. In that way cart and checkout pages can be loaded instantly when your customer navigate to cart/checkout pages.
Price Fragments
If you have a multi-currency store, or use visitors' geolocation to calculate VAT on shop/product pages, you can enable Price Fragments feature, to load prices via AJAX, while the rest of the page can be served from cache.
Developers
Swift Performance AI provides a comprehensive set of hooks and constants that developers can use to extend or modify its functionality. This section documents all available filter hooks, action hooks, and constants.
Filter Hooks
Filter hooks allow you to modify data or functionality. Here's a complete list of filter hooks available in Swift Performance AI. You can use these hooks in your theme's functions.php file or in a custom plugin.
Note: Filter hooks should be added using the add_filter()
WordPress function. The general syntax is:
add_filter('hook_name', 'callback_function', priority, accepted_args);
where priority is optional (default: 10) and accepted_args is optional (default: 1).
swift3_litespeed_cache_rewrites
Controls whether LiteSpeed cache rewrites should be enabled in the .htaccess file. This filter determines if LiteSpeed caching directives are added to or removed from the .htaccess file.
Parameters:
$enabled
(boolean) - Whether cache rewrites are enabled
Default:
Value of swift3_check_option('caching', 'on')
Example:
// Only enable LiteSpeed cache rewrites in production environment
add_filter('swift3_litespeed_cache_rewrites', function($enabled) {
// Check for development environment
if (defined('WP_ENVIRONMENT_TYPE') && WP_ENVIRONMENT_TYPE !== 'production') {
return false;
}
return $enabled;
});
swift3_nginx_cache_rewrites
Controls whether Nginx cache rewrites should be enabled.
Parameters:
$enabled
(boolean) - Whether cache rewrites are enabled
Default:
Value of swift3_check_option('caching', 'on')
Example:
// Only enable Nginx cache rewrites in production environment
add_filter('swift3_nginx_cache_rewrites', function($enabled) {
// Check for development environment
if (defined('WP_ENVIRONMENT_TYPE') && WP_ENVIRONMENT_TYPE !== 'production') {
return false;
}
return $enabled;
});
swift3_deactivate_plugins
Filter the list of plugins to deactivate when there are overlapping functionalities.
Default list includes:
- Swift Performance 2.x
- W3 Total Cache
- Autoptimize
- WP Rocket
- WP Fastest Cache
- WP Super Cache
- Hummingbird
- SG Optimizer
- Cache Enabler
- Breeze
- Nitropack
Parameters:
$plugin_files
(array) - Array of plugin file paths to deactivate
Example:
// Keep Autoptimize active even when Swift Performance is active
add_filter('swift3_deactivate_plugins', function($plugin_files) {
// Find and remove Autoptimize from the list of plugins to deactivate
foreach ($plugin_files as $key => $plugin_file) {
if (strpos($plugin_file, 'autoptimize') !== false) {
unset($plugin_files[$key]);
}
}
return $plugin_files;
});
swift3_varnish_detected
Allows modification of Varnish detection logic.
Parameters:
$detected
(boolean) - Whether Varnish is detected
Default:
Based on HTTP_X_VARNISH header or VARNISH constant
Example:
// Force Varnish detection for specific environments
add_filter('swift3_varnish_detected', function($detected) {
// Force Varnish detection in staging environment
if (defined('WP_ENVIRONMENT_TYPE') && WP_ENVIRONMENT_TYPE === 'staging') {
return true;
}
return $detected;
});
swift3_varnish_not_detected
When Varnish is enabled, Swift will purge Varnish cache if necessary. If the purge request returns an error, Swift will disable Varnish auto purge by default. This filter allows you to override this behavior and keep Varnish enabled even when purge requests fail.
Parameters:
$not_detected
(boolean) - Whether Varnish purge failed (true if failed, which would disable Varnish by default)
Default:
Based on HTTP response code (not 200) or missing x-varnish header in response
Example:
// Keep Varnish enabled even when purge requests fail for specific hosts
add_filter('swift3_varnish_not_detected', function($not_detected) {
// Get the current hostname
$hostname = $_SERVER['HTTP_HOST'];
// List of hosts where we want to keep Varnish enabled regardless of purge status
$keep_varnish_hosts = array('staging.example.com', 'dev.example.com');
// If current host is in our list, keep Varnish enabled
if (in_array($hostname, $keep_varnish_hosts)) {
return false; // Return false to prevent disabling Varnish
}
return $not_detected; // Otherwise use default behavior
});
swift3_cloudflare_detected
Filter whether Cloudflare is detected for the site. Swift Performance uses this to determine if Cloudflare-specific optimizations should be applied.
Parameters:
$detected
(boolean) - Whether Cloudflare is detected
Default:
Based on HTTP_CF_RAY server variable
Example:
// Force Cloudflare detection to be enabled
add_filter('swift3_cloudflare_detected', '__return_true');
// OR
// Force Cloudflare detection to be disabled
add_filter('swift3_cloudflare_detected', '__return_false');
swift3_jet_blog_detected
Filter whether Jet Blog plugin is detected. Swift Performance uses this to apply specific optimizations for Jet Blog plugin.
Parameters:
$detected
(boolean) - Whether Jet Blog plugin is detected
Default:
Based on whether the Jet Blog plugin is active
Example:
// Force Jet Blog detection to be enabled
add_filter('swift3_jet_blog_detected', '__return_true');
// OR
// Force Jet Blog detection to be disabled
add_filter('swift3_jet_blog_detected', '__return_false');
swift3_excluded_edd_pages
Filter the list of Easy Digital Downloads pages to exclude from caching.
Parameters:
$excluded_pages
(array) - Array of EDD page IDs to exclude from caching
Default:
Purchase page, success page, failure page, and purchase history page from EDD settings
Example:
// Add additional EDD pages to exclude from caching
add_filter('swift3_excluded_edd_pages', function($excluded_pages) {
// Add a custom EDD-related page to the exclusion list
$excluded_pages[] = 123; // Page ID of a custom EDD-related page
return $excluded_pages;
});
swift3_excluded_surecart_pages
Filter the list of SureCart pages to exclude from caching.
Parameters:
$excluded_pages
(array) - Array of SureCart page IDs to exclude from caching
Default:
Default SureCart checkout and account pages
Example:
// Add additional SureCart pages to exclude from caching
add_filter('swift3_excluded_surecart_pages', function($excluded_pages) {
// Add a custom SureCart-related page to the exclusion list
$excluded_pages[] = 456; // Page ID of a custom SureCart-related page
return $excluded_pages;
});
swift3_elementor_widget_settings
Filter Elementor widget settings before processing for fragment caching. This allows you to modify widget settings before they are used to create fragment wrappers.
Parameters:
$settings
(array) - The Elementor widget settings$widget_content
(string) - The widget content$that
(object) - The Elementor widget instance
Default:
Original widget settings from $data['settings']
Example:
// Modify Elementor widget settings to force ajaxify for specific widget types
add_filter('swift3_elementor_widget_settings', function($settings, $widget_content, $widget) {
// Force ajaxify for post widgets
if ($widget->get_name() === 'posts' || $widget->get_name() === 'archive-posts') {
$settings['swift-ajaxify'] = 'yes';
}
return $settings;
}, 10, 3);
swift3_elementor_widget_fragment
Filter whether to create a fragment for an Elementor widget. This allows you to control which widgets should be ajaxified even if they have the 'swift-ajaxify' setting enabled.
Parameters:
$create_fragment
(boolean) - Whether to create a fragment for the widget (default: true)$that
(object) - The Elementor widget instance
Default:
true
Example:
// Prevent specific Elementor widgets from being ajaxified
add_filter('swift3_elementor_widget_fragment', function($create_fragment, $widget) {
// Don't create fragments for image widgets
if ($widget->get_name() === 'image') {
return false;
}
// Don't create fragments for widgets in specific sections
$section = $widget->get_parent();
if ($section && $section->get_id() === 'header-section') {
return false;
}
return $create_fragment;
}, 10, 2);
swift3_fragment_callback
Filter the JavaScript callback function that will be executed after a fragment is loaded via AJAX. This allows you to add custom JavaScript functionality to fragments.
Parameters:
$callback
(string) - The JavaScript callback function (default: empty string)$widget_content
(string) - The widget content$that
(object) - The Elementor widget instance
Default:
Empty string
Example:
// Initialize Jet Menu after fragment is loaded via AJAX
add_filter('swift3_fragment_callback', function($callback, $content, $that){
// Check if this is a Jet Menu widget
if (in_array($that->get_name(), array('jet-mobile-menu', 'jet-mega-menu'))){
// Return JavaScript to be executed after fragment loads
// This will initialize Jet Menu if it exists
$callback = '(typeof jetMenu !== \'undefined\' && jetMenu.init())';
}
return $callback;
}, 10, 3);
swift3_should_fragment
Controls whether fragment caching should be enabled globally. This is a master switch for all fragment functionality.
Parameters:
$should_fragment
(boolean) - Whether fragment caching should be enabled
Default:
true unless swift3_skip_optimizer
returns true or nocache
query parameter is present
Example:
// Disable fragment caching for specific pages or user roles
add_filter('swift3_should_fragment', function($should_fragment) {
// Disable fragments for specific page templates
if (is_page_template('template-no-fragments.php')) {
return false;
}
// Disable fragments for editors and administrators
if (current_user_can('edit_posts')) {
return false;
}
// Disable fragments for specific post types
if (is_singular('product')) {
return false;
}
return $should_fragment;
});
swift3_elementor_template_types
Filter the list of Elementor template types and their labels. This is used when displaying template type information in the Swift Performance interface.
Parameters:
$labels
(array) - Associative array of template type keys and their display labels
Default:
array('wp-post' => 'Post', 'wp-page' => 'Page')
Example:
// Add custom Elementor template types to Swift Performance
add_filter('swift3_elementor_template_types', function($labels) {
// Add support for Elementor Pro template types
$labels['section'] = 'Section';
$labels['header'] = 'Header';
$labels['footer'] = 'Footer';
$labels['single'] = 'Single';
$labels['archive'] = 'Archive';
$labels['popup'] = 'Popup';
// Add custom template type
$labels['custom-type'] = 'Custom Template';
return $labels;
});
swift3_elementor_detected
Filter whether Elementor is detected on the site. This allows you to override the automatic detection of Elementor.
Parameters:
$detected
(boolean) - Whether Elementor is detected (default: based on ELEMENTOR__FILE__ constant)
Default:
true if the ELEMENTOR__FILE__ constant is defined
Example:
// Force Swift Performance to use Elementor optimizations even if Elementor is not detected
add_filter('swift3_elementor_detected', '__return_true');
// OR
// Disable Elementor-specific optimizations even when Elementor is installed
add_filter('swift3_elementor_detected', '__return_false');
swift3_excluded_woocommerce_pages
Modifies the list of WooCommerce pages that should be excluded from caching.
Parameters:
$excluded_pages
(array) - Array of page IDs to exclude
Default:
Cart, checkout, and account pages
Example:
// Add additional WooCommerce pages to exclude from caching
add_filter('swift3_excluded_woocommerce_pages', function($excluded_pages) {
// Add the thank you page to excluded pages
$thank_you_page_id = get_option('woocommerce_thanks_page_id');
if ($thank_you_page_id) {
$excluded_pages[] = $thank_you_page_id;
}
// Also exclude the wishlist page if using YITH WooCommerce Wishlist
$wishlist_page_id = get_option('yith_wcwl_wishlist_page_id');
if ($wishlist_page_id) {
$excluded_pages[] = $wishlist_page_id;
}
return $excluded_pages;
});
swift3_woocommerce_price_fragment
Filter whether to create a fragment for WooCommerce prices. This controls whether product prices should be loaded via AJAX (as fragments) or included directly in the cached page.
Parameters:
$create_fragment
(boolean) - Whether to create a fragment for the price (default: true)$product
(WC_Product) - The product object
Default:
true
Example:
// Only create price fragments for variable products
add_filter('swift3_woocommerce_price_fragment', function($create_fragment, $product) {
// Only create fragments for variable products (which may have different prices based on user location)
if ($product->is_type('variable')) {
return true;
}
// For simple products, include the price directly in the cached page
return false;
}, 10, 2);
// OR
// Disable price fragments for specific product categories
add_filter('swift3_woocommerce_price_fragment', function($create_fragment, $product) {
// Get product categories
$terms = get_the_terms($product->get_id(), 'product_cat');
if ($terms && !is_wp_error($terms)) {
foreach ($terms as $term) {
// Don't create fragments for products in the 'fixed-price' category
if ($term->slug === 'fixed-price') {
return false;
}
}
}
return $create_fragment;
}, 10, 2);
swift3_ajax_update_{option}_option
Filter the result of updating an option via AJAX.
swift3_http_request_cache_expiry
Controls the expiration time (in seconds) for cached HTTP requests.
Parameters:
$expiry
(integer) - Default expiry time (300 seconds)$url
(string) - The URL being requested$args
(array) - Request arguments
Example:
// Extend cache expiry for specific API endpoints
add_filter('swift3_http_request_cache_expiry', function($expiry, $url, $args) {
// Cache weather API requests longer (1 hour)
if (strpos($url, 'api.weather.com') !== false) {
return 3600; // 1 hour
}
// Cache other external APIs for 10 minutes
if (strpos($url, 'external-domain.com') !== false) {
return 600; // 10 minutes
}
// Cache WooCommerce API requests for less time
if (strpos($url, 'wc-api') !== false) {
return 60; // 1 minute
}
return $expiry;
}, 10, 3);
swift3_http_request_cache_response
Filter the cached HTTP response before returning it. This allows you to modify or validate the cached response data.
Parameters:
$response
(array) - The cached response data$url
(string) - The URL being requested$args
(array) - Request arguments
Default:
The cached transient value
Example:
// Modify cached API responses to ensure data is fresh
add_filter('swift3_http_request_cache_response', function($response, $url, $args) {
// For weather API responses, check if the data is too old
if (strpos($url, 'api.weather.com') !== false) {
// If the timestamp in the response is more than 1 hour old, return false to force a fresh request
if (isset($response['body']) && is_string($response['body'])) {
$data = json_decode($response['body'], true);
if (isset($data['timestamp']) && ($data['timestamp'] + 3600) < time()) {
return false; // Force a fresh request
}
}
}
return $response;
}, 10, 3);
swift3_http_request_cache_url
Filter the URL used for HTTP request cache key generation. This allows you to normalize URLs to improve cache hit rates.
Parameters:
$url
(string) - The URL being requested$args
(array) - Request arguments
Default:
The original URL
Example:
// Normalize API URLs to improve cache hit rates
add_filter('swift3_http_request_cache_url', function($url, $args) {
// For multilingual sites, remove language code from URL to share cache
if (strpos($url, '/api/') !== false) {
// Remove language path segments like /en/ or /fr/ from the URL
$url = preg_replace('#(https?://[^/]+)/([a-z]{2})/#', '$1/', $url);
}
// Remove tracking parameters that don't affect the response
if (strpos($url, '?') !== false) {
$url_parts = parse_url($url);
if (isset($url_parts['query'])) {
parse_str($url_parts['query'], $params);
// Remove tracking parameters
unset($params['utm_source'], $params['utm_medium'], $params['utm_campaign']);
// Rebuild URL
$url_parts['query'] = http_build_query($params);
$url = Swift3_Helper::build_url($url_parts);
}
}
return $url;
}, 10, 2);
swift3_http_request_cache_args
Filter the arguments used for HTTP request cache key generation. This allows you to normalize or remove request arguments that don't affect the response content.
Parameters:
$args
(array) - Request arguments$url
(string) - The URL being requested
Default:
The original request arguments
Example:
// Clean up request arguments to improve cache hit rates
add_filter('swift3_http_request_cache_args', function($args, $url) {
// Remove non-deterministic headers that don't affect the response
if (isset($args['headers'])) {
// Remove request-specific headers
unset($args['headers']['X-WP-Nonce']);
unset($args['headers']['X-Requested-With']);
// Remove user-specific headers for shared caching
unset($args['headers']['Cookie']);
unset($args['headers']['Authorization']);
}
// For Query Monitor compatibility, remove its added parameters
if (class_exists('QM_Dispatchers')) {
unset($args['_qm_key']);
}
return $args;
}, 10, 2);
swift3_toolbar_is_page_cacheable
Filter whether a page is cacheable as displayed in the Swift Performance toolbar. This allows you to modify the cacheability status shown in the toolbar without affecting the actual caching behavior.
Parameters:
$is_cacheable
(boolean) - Whether the current page is cacheable
Default:
Result of Swift3::get_module('cache')->is_page_cacheable()
Example:
// Always show the current page as cacheable in the toolbar for administrators
add_filter('swift3_toolbar_is_page_cacheable', function($is_cacheable) {
// Only modify the toolbar display for administrators
if (current_user_can('manage_options')) {
return true;
}
return $is_cacheable;
});
// OR
// Show specific pages as non-cacheable in the toolbar for testing purposes
add_filter('swift3_toolbar_is_page_cacheable', function($is_cacheable) {
// Get current URL
$current_url = Swift3_Helper::get_current_url();
// Mark specific test pages as non-cacheable in the toolbar
if (strpos($current_url, '/test-page/') !== false) {
return false;
}
return $is_cacheable;
});
swift3_collage_result_{type}
Filter the result of a collage operation by type. The {type} placeholder is replaced with the specific collage type (e.g., 'admin_bar'). This allows you to modify the HTML content returned by different collage operations.
Parameters:
$result
(string) - The HTML content generated by the collage operation$data
(array) - Data passed to the collage operation
Default:
The HTML content generated by the specific collage operation
Example:
// Modify the admin bar collage content
add_filter('swift3_collage_result_admin_bar', function($result, $data) {
// Remove specific items from the admin bar
$result = preg_replace('/<li id="wp-admin-bar-updates".*?<\/li>/s', '', $result);
// Add custom notification to the admin bar
$result = str_replace('</ul></div>', '<li id="custom-notification"><a href="#">Custom Notification</a></li></ul></div>', $result);
return $result;
}, 10, 2);
swift3_collage_admin_bar_request
Filter the admin bar collage request parameters. This allows you to modify the data used to generate the admin bar fragment request.
Parameters:
$request
(array) - Array containing collage request data: [0] => 'collage', [1] => queried_object_id, [2] => 'admin_bar'
Default:
array('collage', $wp_the_query->queried_object_id, 'admin_bar')
Example:
// Modify the admin bar collage request to include additional data
add_filter('swift3_collage_admin_bar_request', function($request) {
// Add a custom identifier to the request
$request[3] = 'custom_admin_bar';
// Add user role information to the request
if (is_user_logged_in()) {
$user = wp_get_current_user();
$request[4] = $user->roles[0];
}
return $request;
});
swift3_admin_cache_notices
Filter the HTML content of admin notices before they are cached. This allows you to modify, remove, or add notices in the WordPress admin area when using Swift Performance's admin cache.
Parameters:
$notices
(string) - The HTML content of admin notices
Default:
The output buffer content from the admin_notices hook
Example:
// Remove specific admin notices from the cache
add_filter('swift3_admin_cache_notices', function($notices) {
// Remove update notifications
$notices = preg_replace('/<div class="update-nag".*?<\/div>/s', '', $notices);
// Remove specific plugin notices
$notices = preg_replace('/<div class="notice" id="woocommerce-message".*?<\/div>/s', '', $notices);
// Add a custom notice
$custom_notice = '<div class="notice notice-info"><p>This is a custom cached notice.</p></div>';
$notices .= $custom_notice;
return $notices;
});
swift3_admin_cache_menu
Filter the WordPress admin menu array before it is cached. This allows you to modify the admin menu structure when using Swift Performance's admin cache.
Parameters:
$menu
(array) - The global WordPress admin menu array
Default:
The global $menu
array
Example:
// Modify the admin menu before it's cached
add_filter('swift3_admin_cache_menu', function($menu) {
// Remove specific menu items
foreach ($menu as $key => $item) {
// Remove the Comments menu item
if (isset($item[2]) && $item[2] === 'edit-comments.php') {
unset($menu[$key]);
}
// Remove the Tools menu item
if (isset($item[2]) && $item[2] === 'tools.php') {
unset($menu[$key]);
}
}
// Add a custom menu item
$menu[] = array(
0 => 'Custom Menu',
1 => 'read',
2 => 'custom-menu',
3 => '',
4 => 'menu-top',
5 => 'custom-menu-top',
6 => 'dashicons-admin-generic'
);
return $menu;
});
swift3_code_optimizer
Determines whether code optimization should be enabled for the current request.
Parameters:
$enabled
(boolean) - Whether optimization is enabled
Default:
true
Example:
// Disable code optimization for specific post types
add_filter('swift3_code_optimizer', function($enabled) {
global $post;
// Disable for landing pages
if (isset($post) && $post->post_type === 'landing_page') {
return false;
}
// Disable for pages with specific template
if (is_page_template('template-fullwidth.php')) {
return false;
}
// Disable for specific page IDs
if (is_page(array(123, 456, 789))) {
return false;
}
return $enabled;
});
swift3_skip_optimizer
Controls whether optimization should be skipped for the current request. This is a master switch that affects all optimization features including caching, CSS/JS optimization, and fragments.
Parameters:
$skip
(boolean) - Whether to skip optimization (default: false)
Default:
false, but automatically returns true if ?preview
, ?nocache
, or ?swift-test-page
query parameters are present
Example:
// Skip optimization for specific user agents or conditions
add_filter('swift3_skip_optimizer', function($skip) {
// Skip optimization for page builders
if (isset($_GET['elementor-preview']) || isset($_GET['et_fb']) || isset($_GET['fl_builder'])) {
return true;
}
// Skip optimization for specific user roles
if (current_user_can('editor') || current_user_can('shop_manager')) {
return true;
}
// Skip optimization for specific page templates
if (is_page_template('template-custom.php')) {
return true;
}
// Skip optimization based on custom cookie
if (isset($_COOKIE['disable_optimization'])) {
return true;
}
return $skip;
});
swift3_cache_device
Controls the suffix added to cache files to differentiate between device types.
Parameters:
$suffix
(string) - The device suffix, default is '-mobile' for mobile devices when SWIFT3_SEPARATE_DEVICES is defined
Example:
// Create separate cache files for tablets
add_filter('swift3_cache_device', function($suffix) {
// Check if it's a tablet using a detection function
if (function_exists('wp_is_tablet') && wp_is_tablet()) {
return '-tablet';
}
// Otherwise return the default suffix
return $suffix;
});
swift3_gutenberg_block_fragment
Filter whether to create a fragment for a Gutenberg block. This allows you to control which blocks should be loaded via AJAX as fragments.
Parameters:
$create_fragment
(boolean) - Whether to create a fragment for the block (default: true)$block
(array) - The block data array
Default:
true for blocks with the isSwiftPerfrormanceLazyloaded
attribute set to true
Example:
// Prevent specific Gutenberg blocks from being ajaxified
add_filter('swift3_gutenberg_block_fragment', function($create_fragment, $block) {
// Don't create fragments for specific block types
if (isset($block['blockName'])) {
// Don't create fragments for image blocks
if ($block['blockName'] === 'core/image') {
return false;
}
// Don't create fragments for blocks in the 'acf' namespace
if (strpos($block['blockName'], 'acf/') === 0) {
return false;
}
}
// Don't create fragments for blocks with specific attributes
if (isset($block['attrs']['data-no-fragment']) && $block['attrs']['data-no-fragment']) {
return false;
}
return $create_fragment;
}, 10, 2);
swift3_shortcode_fragment
Filter whether to create a fragment for a shortcode. This allows you to control which shortcodes should be loaded via AJAX as fragments, even if they are in the shortcode fragments list.
Parameters:
$create_fragment
(boolean) - Whether to create a fragment for the shortcode (default: true)$shortcode
(string) - The shortcode tag$atts
(array) - The shortcode attributes
Default:
true for shortcodes listed in the shortcode fragments setting
Example:
// Conditionally prevent specific shortcodes from being ajaxified
add_filter('swift3_shortcode_fragment', function($create_fragment, $shortcode, $atts) {
// Don't create fragments for the contact form shortcode on the contact page
if ($shortcode === 'contact-form-7' && is_page('contact')) {
return false;
}
// Don't create fragments for gallery shortcodes with specific IDs
if ($shortcode === 'gallery' && isset($atts['id'])) {
$excluded_gallery_ids = array(123, 456, 789);
if (in_array($atts['id'], $excluded_gallery_ids)) {
return false;
}
}
// Don't create fragments for any shortcodes in the sidebar
global $wp_current_filter;
if (in_array('dynamic_sidebar_before', $wp_current_filter) || in_array('dynamic_sidebar_after', $wp_current_filter)) {
return false;
}
return $create_fragment;
}, 10, 3);
Action Hooks
Action hooks allow you to execute custom code at specific points in Swift Performance's execution. Here's a complete list of action hooks available in Swift Performance AI. You can use these hooks in your theme's functions.php file or in a custom plugin.
Note: Action hooks should be added using the add_action()
WordPress function. The general syntax is:
add_action('hook_name', 'callback_function', priority, accepted_args);
where priority is optional (default: 10) and accepted_args is optional (default: 1).
swift3_option_{key}_updated
Triggered when a specific Swift Performance option is updated. Replace {key}
with the actual option name.
Parameters:
$value
- The new value for the option
swift3_option_updated
Triggered when any option is updated.
Parameters:
$key
(string) - The option key that was updated$value
(mixed) - The new value for the option
swift3_collage_before_{type}
Triggered before a collage operation of a specific type. The {type} placeholder is replaced with the specific collage type (e.g., 'admin_bar').
Parameters:
$data
(array) - Data passed to the collage operation
swift3_before_collage_admin_bar_assets
Triggered before loading admin bar assets in collage.
swift3_cache_done
Fired when a URL has been successfully cached.
Parameters:
$url
(string) - The URL that was cached
swift3_transient_status
Triggered when a transient status changes.
Parameters:
$old_status
(integer) - The previous status code$new_status
(integer) - The new status code$url
(string) - The URL associated with the status change
swift3_warmup_post_types
Filter the post types that should be included in the cache warmup process. This allows you to add or remove post types from the warmup queue.
Parameters:
$post_types
(array) - Array of post type names to include in warmup
Default:
All public and publicly queryable post types, excluding those in the exclusion settings
swift3_warmup_add_url
Triggered when a URL is added to the cache warmup queue.
Parameters:
$url
(string) - The URL being added to the warmup queue$priority
(integer) - The priority of the URL in the queue$post_id
(integer|null) - The post ID associated with the URL, if available
swift3_get_install_steps
Triggered when getting installation steps.
swift_after_header
Triggered after the header is processed by the optimizer.
swift3_code_optimizer_before_check_plugin
Triggered before checking a plugin in the code optimizer.
swift3_rest_action_{path}
Triggered for a specific REST API path.
swift3_before_shortcode_fragment_callback
Triggered before a shortcode fragment callback.
swift3_config_api_test_error
Triggered when an API test encounters an error.
swift3_config_api_test
Triggered when an API test is performed.
swift3_generate_rewrites_{server}
Triggered when generating rewrites for a specific server type.
swift3_remove_rewrites_{server}
Triggered when removing rewrites for a specific server type.
swift3_development_mode_deactivated
Triggered when development mode is deactivated.
swift3_development_mode_activated
Fired when development mode is activated.
swift3_htaccess_compression
Triggered when generating htaccess compression rules.
swift3_nginx_compression
Triggered when generating Nginx compression rules.
swift3_nginx_browser-cache
Triggered when generating Nginx browser cache rules.
swift3_page_discovered
Triggered when a new page is discovered.
swift3_invalidate_cache
Triggered when cache is invalidated for a URL.
swift3_invalidate_object
Triggered when an object's cache is invalidated.
swift3_purge_cache
Triggered when cache is purged for a specific URL.
Parameters:
$url
(string) - The URL for which cache is being purged$remove_warmup
(boolean) - Whether to remove the URL from warmup queue
swift3_litespeed_cache_headers
Triggered when setting LiteSpeed cache headers.
Constants
Swift Performance AI uses various constants to control its behavior. You can define these constants in your wp-config.php file to override the default values. All constants use the SWIFT3_
prefix.
Note: To define a constant, add it to your wp-config.php file before the line that says "That's all, stop editing! Happy publishing."
SWIFT3_LIMITED_RESOURCES
Shorthand for limited resources mode. When defined, it automatically enables SWIFT3_DISABLE_LOCAL_WEBP
and increases SWIFT3_PREBUILD_INTERMISSION
to 2,500,000 microseconds (2.5 seconds).
This is useful for shared hosting environments or servers with limited CPU/memory resources.
Default:
Not defined by default
Example:
// Add to wp-config.php for shared hosting environments
define('SWIFT3_LIMITED_RESOURCES', true);
SWIFT3_DISABLE_LOCAL_WEBP
When defined as true, disables the local generation of WebP images. This can be useful on servers with limited resources or where image processing is problematic.
Default:
false
Example:
// Disable WebP conversion on the server
define('SWIFT3_DISABLE_LOCAL_WEBP', true);
SWIFT3_PPTO
API timeout in seconds. This controls how long the plugin will wait for API poll responses. If your server has connectivity issues, increasing this value can help with API reliability.
Default:
600 (10 minutes)
Example:
// Increase API timeout to 15 minutes for slow connections
define('SWIFT3_PPTO', 900);
SWIFT3_WARMUP_POST_TYPE_LIMIT
Sets the maximum number of URLs per post type that will be added to the initial warmup table. For sites with many posts, increasing this value ensures more content is cached.
Default:
1000
Example:
// Increase limit for sites with many posts
define('SWIFT3_WARMUP_POST_TYPE_LIMIT', 2000);
SWIFT3_WARMUP_LIMIT
Sets the maximum total number of URLs that will be added to the initial warmup table. This is a global limit across all post types.
For large sites with many pages, you might want to increase this value to ensure comprehensive caching.
Default:
5000
Example:
// Increase global warmup limit for large sites
define('SWIFT3_WARMUP_LIMIT', 10000);
SWIFT3_MAX_URL_LENGTH
Defines the maximum length of URLs that Swift Performance will cache. URLs exceeding this length will be excluded from caching.
This is particularly useful for sites with complex URL structures or extensive query parameters. Increasing this value allows caching of longer URLs, but may increase disk usage.
Default:
255
Example:
// Increase max URL length for complex URLs with many parameters
define('SWIFT3_MAX_URL_LENGTH', 500);
SWIFT3_CACHE_LIFESPAN
Sets the default cache lifespan in seconds. After this period, cached pages will be automatically regenerated.
For sites with frequently changing content, a shorter lifespan may be appropriate. For more static sites, a longer lifespan can reduce server load.
Default:
43200 (12 hours)
Example:
// Set cache lifespan to 1 day
define('SWIFT3_CACHE_LIFESPAN', 86400);
SWIFT3_PREBUILD_INTERMISSION
Sets the pause time in microseconds between prebuild requests. This helps prevent server overload during cache warming.
For shared hosting or limited resource environments, increasing this value reduces server load but slows down the prebuild process.
Default:
500000 (0.5 seconds)
Example:
// Increase pause time for shared hosting
define('SWIFT3_PREBUILD_INTERMISSION', 1000000);
SWIFT3_WEBP_QUALITY
Sets the quality level for WebP image conversion. Values range from 0 (worst quality, smallest file size) to 100 (best quality, largest file size).
The default value of 83 provides a good balance between quality and file size. Adjust based on your specific needs.
Default:
83
Example:
// Increase WebP quality for photography sites
define('SWIFT3_WEBP_QUALITY', 90);
// Decrease WebP quality to prioritize smaller file sizes
// define('SWIFT3_WEBP_QUALITY', 75);
SWIFT3_DISABLE_LSCACHE
When defined as true, disables LiteSpeed Cache integration. This is useful if you're experiencing conflicts with LiteSpeed Cache.
Default:
false
Example:
// Disable LiteSpeed Cache integration
define('SWIFT3_DISABLE_LSCACHE', true);
DOING_FRAGMENTS
This is an internal constant that indicates Swift Performance is currently processing fragments. It's primarily used by the plugin itself.
Developers can check for this constant in their code to modify behavior when fragments are being processed.
Default:
Not defined by default
Example:
// Check if Swift Performance is processing fragments
if (!defined('DOING_FRAGMENTS')) {
// Code that should not run during fragment processing
}
DISABLE_SYMLINK
When defined, prevents Swift Performance from using symbolic links for optimized images.
This is useful on hosting environments where symlinks are not supported or restricted. When disabled, the plugin will use direct file copies instead.
Default:
Not defined by default
Example:
// Disable symbolic links for image optimization
define('DISABLE_SYMLINK', true);
DOING_ADMIN_CACHE
An internal constant that indicates Swift Performance is currently processing the WordPress admin area cache.
Like DOING_FRAGMENTS, this is primarily used by the plugin itself, but developers can check for it to modify behavior during admin cache processing.
Default:
Not defined by default
Example:
// Check if Swift Performance is processing admin cache
if (!defined('DOING_ADMIN_CACHE')) {
// Normal admin processing code
}
DISABLE_TIMEOUT
When defined, prevents Swift Performance from extending PHP execution time limits for long-running processes.
By default, Swift Performance tries to extend timeouts for operations like cache warmup. This constant is useful on hosts where modifying the timeout is not allowed or causes issues.
Default:
Not defined by default
Example:
// Prevent Swift Performance from modifying PHP timeout
define('DISABLE_TIMEOUT', true);
DISABLE_TOOLBAR
When defined, completely disables the Swift Performance toolbar that appears at the bottom of the page for administrators.
This is useful in development environments where the toolbar might interfere with other tools, or if you simply prefer not to see it.
Default:
Not defined by default
Example:
// Disable the Swift Performance toolbar
define('DISABLE_TOOLBAR', true);
INVALIDATE_CACHE_ON_COMMENT
When defined, forces Swift Performance to invalidate the cache for a post when a new comment is submitted.
By default, Swift Performance does not invalidate cache on comments to prevent cache thrashing on popular posts. Enable this if comment display is critical for your site.
Default:
Not defined by default
Example:
// Force cache invalidation when comments are posted
define('INVALIDATE_CACHE_ON_COMMENT', true);