Powered Cache Documentation https://docs.poweredcache.com Just another WordPress site Wed, 19 Nov 2025 08:31:46 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 LCP Optimization https://docs.poweredcache.com/lcp-optimization/ Wed, 19 Nov 2025 08:31:45 +0000 https://docs.poweredcache.com/?p=443

This feature is available in Powered Cache Premium and is designed to help the browser get your above-the-fold content on screen faster by:

  • Detecting the Largest Contentful Paint (LCP) image
  • Preloading that image with proper hints
  • Optionally preloading critical fonts
  • Coordinating with Critical CSS to prioritize key styles

It works automatically on compatible front-end page loads once enabled in your Powered Cache settings.

How LCP Optimization works

Internally, the feature runs as an output buffer on front-end HTML requests and makes three passes over the generated HTML:

  1. Preload the LCP image
  2. Preload critical fonts (optional, via filter)
  3. Prioritize Critical CSS (when Critical CSS is enabled)

It does not run:

  • In the WordPress dashboard (is_admin())
  • On REST API requests
  • On trackbacks, robots, or preview pages
  • On non-GET requests

Developers can also programmatically skip it using powered_cache_skip_lcp_optimization filter.

1. LCP image detection and preloading

How the LCP image is detected

The feature parses the final HTML and uses a few heuristics to guess the most likely LCP candidate:

  1. <picture> elements (highest priority)
    It looks for the first <picture> in common content areas:
    • //main//picture[1]
    • //article//picture[1]
    • first <section> and then top-level <picture>
    If an <img> is inside that <picture>, its URL, srcset, and sizes are used.
  2. Hero / main content images If no <picture> is found, it checks for the first <img> in:
    • <main>
    • <article>
    • containers with hero or banner in the class name
    • the first <section>
    • finally, the first <img> in <body>
    Images inside <picture> elements are skipped here because they are already handled in step 1.
  3. Video posters If a <video> tag has a poster attribute, that poster can be used as an LCP candidate.

Once a candidate is found, the plugin extracts:

  • url (image URL)
  • srcset (if present)
  • sizes (if present)
  • type (MIME type based on the file extension: jpeg, png, webp, avif, svg, etc.)

Developers can override or completely disable the detection result via the powered_cache_lcp_image filter.

Preloading the LCP image

If an LCP candidate is found and not already preloaded, Powered Cache Premium injects a <link> tag into the <head>:

<!-- LCP Optimization: Image Preload by Powered Cache Premium -->
<link
  rel="preload"
  as="image"
  href="proxy.php?url=https://example.com/path/to/image.jpg"
  imagesrcset="..."
  imagesizes="..."
  type="image/jpeg"
  fetchpriority="high">

Key points:

  • It checks existing <link rel="preload"> or <link rel="prefetch"> tags to avoid duplicates.
  • fetchpriority="high" is added to further hint that this image is critical.
  • If srcset or sizes are available, they are passed as imagesrcset and imagesizes attributes.

You can adjust the attributes via the powered_cache_lcp_preload_attributes filter.


2. External domains and preconnect hints

If the detected LCP image (or any image in its srcset) is served from an external domain (for example, a CDN), that domain is tracked internally.

Later, Powered Cache Premium adds preconnect hints for these domains through the standard wp_resource_hints filter:

add_filter( 'wp_resource_hints', [ $lcp, 'add_resource_hints' ], 10, 2 );

For relation type preconnect:

  • Detected external origins used by LCP-critical images and fonts are added.
  • Developers can add their own origins via the powered_cache_lcp_preconnect_domains filter.
  • Duplicates are removed before output.

This helps the browser open connections early to important external hosts.


3. Critical font preloading (optional)

Font preloading is disabled by default and controlled entirely by a filter.

Enabling font preloading

Developers can enable font preloading with:

add_filter( 'powered_cache_enable_lcp_font_preload', '__return_true' );

How font preloading works

When enabled:

  1. The HTML is scanned for inline <style> blocks.
  2. Inside those styles, the plugin looks for @font-face declarations.
  3. It extracts url(...) values and optional format(...) descriptors.
  4. It determines a MIME type from the format or file extension.
  5. Only modern formats are considered for preloading:
    • font/woff2
    • font/woff
  6. The number of fonts to preload is capped (default: 2) and can be changed via: add_filter( 'powered_cache_lcp_max_fonts_to_preload', function () { return 3; // for example } );

For each selected font, a preload tag like this is injected into the <head>:

<!-- LCP Optimization: Font Preload by Powered Cache Premium -->
<link
  rel="preload"
  as="font"
  href="proxy.php?url=https://example.com/fonts/myfont.woff2"
  type="font/woff2"
  crossorigin="anonymous">

You can modify attributes with the powered_cache_lcp_font_preload_attributes filter, and you can adjust or fully override the font list with powered_cache_lcp_font_urls.

External font hosts (for example, a font CDN) are also added to the preconnect list.


4. Critical CSS prioritization

The LCP Optimization feature also coordinates with Critical CSS, when it is enabled in Powered Cache settings.

Requirements

  • critical_css must be enabled in the plugin settings.
  • LCP CSS optimization is on by default, but controlled by a filter.

To control it:

// Disable LCP CSS optimization
add_filter( 'powered_cache_enable_lcp_css_optimization', '__return_false' );

What it does

When active:

  1. The plugin looks only at the <head> part of the HTML for performance reasons.
  2. It searches for <link> tags that match one or more patterns supplied by the
    powered_cache_lcp_priority_css_patterns filter. By default, it includes: 'wp-content\/themes\/[^\/]+\/style\.css' // Main theme style.css
  3. For matching <link> tags that do not already have a fetchpriority attribute, it rewrites them as: <!-- LCP Optimization: CriticalCSS Preloaded by Powered Cache Premium --> <link rel="stylesheet" href="proxy.php?url=..." fetchpriority="high">

This hints to the browser that those stylesheets are especially important for rendering.

Developers can expand or change which CSS files are treated as high priority by adjusting the regex patterns passed to powered_cache_lcp_priority_css_patterns.


When LCP Optimization runs (and when it does not)

LCP Optimization processing is only started when:

  • The internal setting enable_lcp_optimization is truthy, or
  • A developer explicitly enables it via the powered_cache_enable_lcp_optimization filter.

Additionally, it runs only when:

  • Request method is GET
  • It is not a REST API request
  • It is not is_admin(), is_trackback(), is_robots(), or is_preview()
  • The output looks like HTML (contains <html or <!doctype)

If any of those conditions are not met, the HTML output is returned untouched.


Skipping LCP Optimization for specific pages

You may want to disable LCP Optimization under certain conditions, for example:

  • On specific URLs
  • For logged-in users
  • For particular post types

You can do that via the powered_cache_skip_lcp_optimization filter:

add_filter( 'powered_cache_skip_lcp_optimization', function ( $skip ) {
    if ( is_user_logged_in() ) {
        return true;
    }

    if ( is_page( 'my-custom-page' ) ) {
        return true;
    }

    return $skip;
} );

Returning true skips the entire LCP Optimization process for that request.


Developer filters and hooks

Here is a summary of the main hooks available for customization.

Enable or disable the feature globally

/**
 * Enable or disable LCP optimization (overrides settings)
 */
add_filter( 'powered_cache_enable_lcp_optimization', function ( $enabled ) {
    return true; // force enable, for example
} );

Skip LCP optimization for certain requests

add_filter( 'powered_cache_skip_lcp_optimization', function ( $skip ) {
    // Your conditions here
    return $skip;
} );

Override detected LCP image

add_filter( 'powered_cache_lcp_image', function ( $lcp_image, $html ) {
    // Example: force a specific hero image on the front page
    if ( is_front_page() ) {
        return [
            'url'    => 'https://example.com/path/to/hero.webp',
            'srcset' => '',
            'sizes'  => '',
            'type'   => 'image/webp',
        ];
    }

    return $lcp_image;
}, 10, 2 );

Customize LCP image preload attributes

add_filter( 'powered_cache_lcp_preload_attributes', function ( $attributes, $lcp_data ) {
    // Add or change attributes if needed
    // $attributes['media'] = '(min-width: 768px)';
    return $attributes;
}, 10, 2 );

Add extra preconnect domains

add_filter( 'powered_cache_lcp_preconnect_domains', function ( $domains ) {
    $domains[] = 'https://cdn.example.com';
    return $domains;
} );

Enable font preloading

add_filter( 'powered_cache_enable_lcp_font_preload', '__return_true' );

Adjust font list or limit

// Change max number of fonts to preload
add_filter( 'powered_cache_lcp_max_fonts_to_preload', function () {
    return 3;
} );

// Inspect or adjust detected fonts
add_filter( 'powered_cache_lcp_font_urls', function ( $fonts, $html ) {
    // $fonts is an array of [ 'url' => ..., 'type' => ... ]
    return $fonts;
}, 10, 2 );

Customize font preload attributes

add_filter( 'powered_cache_lcp_font_preload_attributes', function ( $attributes, $font_data ) {
    // Example: change crossorigin mode
    // $attributes['crossorigin'] = 'use-credentials';
    return $attributes;
}, 10, 2 );

Control which CSS files get fetchpriority="high"

add_filter( 'powered_cache_lcp_priority_css_patterns', function ( $patterns ) {
    // Add your own patterns (regex without delimiters)
    $patterns[] = 'wp-content\/plugins\/my-builder\/assets\/css\/frontend\.css';
    return $patterns;
} );

Notes and best practices

  • LCP Optimization is an advanced feature intended to complement your existing caching and optimization setup.
  • It relies on output buffering and HTML parsing, so it is most suitable for standard front-end page responses.
  • When combining it with other optimization plugins or custom output filters, it is a good idea to test key templates (home, blog, product pages, etc.) to ensure everything renders as expected.

You can now wire this up in your docs site (for example under a “Premium Features → Automatic LCP Optimization” section) and trim or expand the developer examples depending on how deep you want the public documentation to go.

]]>
Bypass Functionality in Powered Cache https://docs.poweredcache.com/bypass-functionality-in-powered-cache/ Wed, 06 Nov 2024 19:54:17 +0000 https://docs.poweredcache.com/?p=426 Powered Cache offers a bypass feature that allows you to view your site without caching or optimization. This is particularly useful if you want to check how the site looks and performs without any caching or optimizations applied by the plugin.

How to Use the Bypass Functionality

To bypass the caching, you can add a simple parameter to your URL:

  1. Go to the page you want to view without caching.
  2. Append ?nopoweredcache=1 to the URL.
https://example.com?nopoweredcache=1

Once you add this parameter to the URL, Powered Cache will temporarily skip caching for that specific page request. This allows you to see the “raw” version of the page without caching or optimizations, which can help in debugging or comparing the optimized vs. non-optimized versions of your site.

When to Use Bypass

  • Testing: See how your website looks and performs without any caching or optimizations.
  • Debugging: Identify any issues on the page that might be caused by caching or other optimization processes.

This feature is helpful for administrators, developers, and anyone who needs a quick way to view an unoptimized version of a page without altering the overall cache settings for the entire site.

]]>
Protect Cache Directory: Securing Sensitive Cached Files for Your Website https://docs.poweredcache.com/protect-cache-directory/ Tue, 29 Oct 2024 14:53:45 +0000 https://docs.poweredcache.com/?p=415 Caching improves website performance by serving pre-generated content, reducing the load on the server and speeding up response times. However, caching can also store sensitive information in cached files, particularly when users are logged in. Protecting these files is essential to prevent unauthorized access and keep user data safe.

This guide explains why protecting your cache directory matters and provides a step-by-step approach for securing sensitive cache files for both Apache and Nginx setups. Let’s dive into the reasons and methods for implementing cache directory protection effectively.

Why Protect the Cache Directory?

When caching plugins or systems create cached versions of pages, they generate static HTML files that are saved in a cache directory, usually under wp-content/cache/ or a similar folder. It’s not a critical problem if you are just caching publicly accessible pages, however if you want to enable logged-in user caching, it becomes critical.

How to Protect the Cache Directory

To secure the cache directory and avoid exposing sensitive information, you need to configure both Apache or Nginx to restrict access to specific cached files while allowing public cache files to be served as intended.

Step 1: Apache Configuration with Powered Cache

If you are using Apache to serve cache files, Powered Cache can automatically create .htaccess configurations in your cache directory. This file helps protect sensitive cache files for logged-in users without additional manual setup.

Default Powered Cache .htaccess Protection

<IfModule mod_autoindex.c>
    Options -Indexes
</IfModule>

<FilesMatch "^.*-user_.*\.(html|html\.gz)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

Powered Cache generates an .htaccess file with rules that block access to logged-in user cache files (those that contain patterns like -user_ in the filename, e.g., index-https-user_admin-12345.html.gz).

Customizing .htaccess Rules

If you need to adjust these automatic rules, you can use the powered_cache_cache_dir_htaccess_file_content filter to modify the contents of the .htaccess file. This allows you to fine-tune security settings while still benefiting from Powered Cache’s automatic file management.

Example usage:

add_filter('powered_cache_cache_dir_htaccess_file_content', function ($content) {
// Customize the default .htaccess content here
$content .= "\n# Additional custom rules\n";
return $content;
});

With this filter, you can add or modify rules as needed for your specific security requirements. After making any modifications, Powered Cache will regenerate the .htaccess file with your customizations.

Step 2: Protecting the Cache Directory in Nginx

If you are using Nginx alongside Apache, Nginx may be configured to serve cached static files directly, bypassing Apache and the .htaccess rules. To secure cached files in this configuration, you need to add equivalent restrictions directly to the Nginx configuration.

Nginx Configuration to Restrict Sensitive Cached Files

  1. Locate Your Nginx Configuration File: Open the configuration file for your site (commonly found in /etc/nginx/sites-available/your-site.conf).
  2. Add a Location Block to Restrict Access to cache files containing -user_ in their filename:
location ^~ /wp-content/cache/powered-cache/ {
    location ~* "-user_.*\.(html|html\.gz)$" {
        deny all;
    }
}

Reload Nginx to apply your changes:

sudo systemctl reload nginx

This setup will block public access to files that match the sensitive cache pattern, while allowing Nginx to continue serving general cache files. If you feel comfortable, you can block the all caching directory like:

location ^~ /wp-content/cache/powered-cache/ {
    allow 127.0.0.1;       # Allow access from localhost
    deny all;              # Deny access to all other IPs
}

Step 3: Testing Your Configuration

To verify that your protection rules are working as expected:

  1. Access a public cache file (e.g., index-https.html) and ensure it loads as expected.
  2. Attempt to access a logged-in cache file with -user_ in the filename (e.g., index-https-user_admin-12345.html). This should return a 403 Forbidden error.

Conclusion

Protecting your cache directory from unauthorized access is a critical part of securing your website. Powered Cache provides automatic .htaccess rules for Apache that can be customized via the powered_cache_cache_dir_htaccess_file_content filter, making it easy to manage sensitive cached content. For Nginx setups, adding direct restrictions ensures that only public cache files are served while keeping user-specific cache files private.

By implementing these steps, you’ll have a secure and efficient caching system that protects user privacy without sacrificing website performance.

]]>
Replace YouTube Iframes with Preview Image https://docs.poweredcache.com/replace-youtube-iframes-with-preview-image/ Wed, 07 Feb 2024 15:21:47 +0000 https://docs.poweredcache.com/?p=374 This feature enhances webpage performance by replacing YouTube iframe embeds with clickable preview images. Videos load and play only when users click the preview, ensuring faster page loads and reduced bandwidth usage.

Enable “Replace Youtube videos by thumbnail.” option that is located under the Lazy Load settings.

Once you enabled this feature, you don’t need anything to do. It will automatically replace YouTube iframe with their thumbnails, and you can verify by checking your networks tab in devtools.

]]>
Disable Lazy Load on specific images https://docs.poweredcache.com/disable-lazy-load-on-specific-images/ Wed, 20 Dec 2023 15:10:17 +0000 https://docs.poweredcache.com/?p=332 You can easily skip lazy-load for specific images like this:

add_filter( 'powered_cache_lazy_load_skip_classes', function ( $skipped_classes ) {
	$skipped_classes[] = 'my-custom-class-for-skip-lazy';

	return $skipped_classes;
} );

By default, images assigned to the “lazy” class are not lazy-loaded. As an alternative, you can assign your images to this class.

If your goal is to skip lazy-loading only for images above the fold, you can configure the number of images to skip in the settings:

]]>
Ip Addresses https://docs.poweredcache.com/ip-addresses/ Mon, 11 Dec 2023 08:40:54 +0000 https://docs.poweredcache.com/?p=328 Our services, including Critical CSS and UCSS, require a publicly accessible website to function. If your website blocks certain countries or has some sort of WAF rules that prevent our servers from accessing your website, you might not be able to use those services.

Here are the ip addresses you can add to your allowed list:

65.109.13.14
157.90.241.2
5.161.68.159

]]>
Rewrite File Optimizer https://docs.poweredcache.com/rewrite-file-optimizer/ Tue, 31 Oct 2023 14:16:33 +0000 https://docs.poweredcache.com/?p=317 Powered Cache relies on the file-optimizer.php file, found in the plugin’s ‘includes’ directory, for optimizing CSS and JS files. Modifying the file optimizer offers several benefits:

  • Enhances CDN Compatibility: Some CDN services may bypass requests when they detect a “.php” in the resource URL. Rewriting the file optimizer resolves this issue.
  • Addresses WAF Rules: If you have set up Web Application Firewall (WAF) rules that prevent file-optimizer.php from executing, using a rewrite can circumvent this limitation.
  • Improved Resource Naming: Utilizing rewrite rules allows for more intuitive and organized naming of related resources.

Example URL Without rewrite:

https://example.com/wp-content/plugins/powered-cache/includes/file-optimizer.php??/wp-includes/css/dashicons.css,/wp-includes/css/admin-bar.css?m=1677524837&minify=1

Example URL With rewrite:

https://example.com/_static/??/wp-includes/css/dashicons.css,/wp-includes/css/admin-bar.css?m=1677524837&minify=1

If your server is compatible with .htaccess and you’ve enabled automatic .htaccess configuration, simply activating this feature is all you need to do. However, if you’d rather handle rewrite rules manually, you can apply the following code snippets:

Apache/LiteSpeed:

<IfModule mod_rewrite.c>
  # Enable rewrite engine
  RewriteEngine On
  # Redirect all requests starting with /_static/
  RewriteRule ^_static/.* wp-content/plugins/powered-cache/includes/file-optimizer.php [L]
</IfModule>

Nginx:

location /_static/ {
        fastcgi_pass unix:/var/run/fastcgi.sock;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/wp-content/plugins/powered-cache/includes/file-optimizer.php;
}

If you are using runcloud for server management, then add this as a custom nginx rule with choosing “location.main-before” for the location

location /_static/ {
        fastcgi_pass unix:/var/run/{APP_NAME}.sock;
        include /etc/nginx-rc/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME  $document_root/wp-content/plugins/powered-cache/includes/file-optimizer.php;
}
]]>
Image Dimensions https://docs.poweredcache.com/image-dimensions/ Wed, 30 Aug 2023 22:20:53 +0000 https://docs.poweredcache.com/?p=290

When a browser renders a web page, it initially loads the HTML and then pauses to download the images. If the dimensions for the images are specified, browsers can allocate the necessary space for those images on the page.

If the dimensions for an image aren’t predetermined, then the browser will adjust the existing content to make space for the image as it gets downloaded. These layout changes can result in a less-than-ideal experience for the visitor.

This feature aims to resolve the following suggestions from GTmetrix and PageSpeed Insights:

  • Use explicit width and height on image elements
  • Cumulative layout shift

How does it work?

Powered Cache checks the HTML output of the page, detects the images that don’t have width and height attributes and alters them by calculating the size.

For example, if your page has

<img src="proxy.php?url=https://www.example.com/wp-content/uploads/2023/08/dummy-image.jpg">

It will be updated like:

<img src="proxy.php?url=https://www.example.com/wp-content/uploads/2023/08/dummy-image.jpg" width="1024" height="641">

Tips:

  • If you want to skip a particular image while keeping this feature enabled, you can add data-skip-image-dimensions attribute to your image tag. Or using powered_cache_skip_adding_missing_image_dimensions filter to exclude specific images.
  • This feature will not work for logged-in users when logged-in user cache is disabled. (calculating the image size of external resources might take a longer time, which can cause more problems than it solves)

]]>
Prefetch Links https://docs.poweredcache.com/prefetch-links/ Wed, 30 Aug 2023 22:00:29 +0000 https://docs.poweredcache.com/?p=288 This feature aims to improve user experience by enhancing the performance of your website. The Prefetch Links feature will automatically prefetch URLs for links that appear in the viewport during idle time, resulting in significantly faster subsequent page loads.

  • This feature will be inactive if it detects that the user is on a slow network or operating under a data plan.
  • wp-admin, external links, or the links with a query string will excluded

Prefetching Custom URLs

Either using a helper method:

\PoweredCachePremium\LinkPrefetcher::prefetch($url, $is_priority);

Or using “powered_cache_link_prefetch_options” filter

add_filter( 'powered_cache_link_prefetch_options', function ( $options ) {
	$urls[] = 'https://plugindevel.test/2020/01/';

	$options['urls'] = $urls;

	return $options;
} );

Plugin compatibility

This feature eliminates the necessity for the following plugins. If any of these plugins are detected, you will receive a prompt to deactivate them:

  • Quicklink
  • Flying Pages
  • instant.page

]]>
Page Cache Purging on Large Scale https://docs.poweredcache.com/page-cache-purging-on-large-scale/ Tue, 16 May 2023 09:17:36 +0000 https://docs.poweredcache.com/?p=271 Page cache purging is a vital process in the lifecycle of any website powered by a content management system. It involves clearing out the stored (or cached) versions of your web pages, to ensure that users are always served the most recent content.

In large-scale web applications, managing cache purging can become a considerable task due to the sheer amount of data. Powered Cache, an all-in-one WordPress caching plugin, provides solutions to deal with this effectively. This document discusses how to implement page cache purging on a large scale using Powered Cache.

1. Server-side Cron

One approach to handle this is using a server-side cron job. Cron is a time-based job scheduler in Unix-like operating systems. Users can schedule jobs (commands or scripts) to run periodically at fixed times, dates, or intervals.

The following command can be used to find and delete all cache files older than 300 minutes (5 hours):

find /var/www/wp-content/cache/* -mmin +300 -type f -delete

Here’s a quick breakdown of the command:

  • find: This is the command that will search for files in a directory.
  • /var/www/wp-content/cache/*: This is the directory where Powered Cache stores its cached files.
  • -mmin +300: This finds files that were last modified more than 300 minutes ago.
  • -type f: This ensures the command only targets files and not directories.
  • -delete: This deletes the files that meet the criteria.

You can add this command to your server’s crontab to run it regularly. This way, any cache files older than the specified time will be automatically deleted.

2. Async Cache Cleaning in Powered Cache 2.3

As of version 2.3, Powered Cache includes a feature called “Async Cache Cleaning”. This feature enables the plugin to perform cache purging in the background.

To enable this feature:

  1. From your WordPress dashboard, go to “Powered Cache”.
  2. In the “Misc” tab, look for “Async Cache Cleaning”.
  3. Check the box next to “Enable async cache clean-up.”.
  4. Click “Save Changes”.

With this feature enabled, Powered Cache will automatically manage the cache purging process for you. This reduces the server load and ensures a smoother experience for your website visitors.

]]>