WP Manifestindependent plugin directory
manifest / performance / svg-inline-cache-manager

SVG Inline Cache Manager

Optimises rendering of remote SVGs by caching them locally and serving them as inline SVGs. Improves performance and enables CSS styling without delays caused by repeated asset downloads.

★ 0stars
1.3.1latest · 1 year ago

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/pds-uk/svg-inline-cache-manager/archive/refs/heads/main.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

Description: A WordPress plugin that optimises the get_attached_file function for remote SVGs by caching them locally. This improves performance, enables CSS styling through inline SVGs, and ensures flexibility for developers to extend functionality.


Key Features

🔄 Enhances get_attached_file

  • Automatically caches remote SVG files locally by hooking into WordPress’s get_attached_file function.
  • Ensures cached files are served locally, improving performance and reducing network requests.

🎨 Inline SVG Rendering

  • Serves SVGs inline in the DOM when developers call custom logic (e.g., using helper functions).
  • Allows full CSS styling and animations directly on SVG content.

⏱ Configurable Cache Duration

  • Use the SVG_CACHE_HOURS environment variable to set the duration (in hours) for how long SVG files are cached.
  • Defaults to 72 hours if the variable is not set.

📂 Configurable Cache Directory

  • Use the SVG_CACHE_PATH environment variable to define a custom directory for storing cached SVGs.
  • Defaults to wp-content/uploads/cached_svgs/ if not set.

🧹 Automatic Cache Clearing

  • Clears the cache when WordPress Customizer settings are saved, ensuring updates are reflected immediately.

⚡ Developer-Friendly Design

  • Designed to modify only the get_attached_file function.
  • Offers a helper function, get_inline_svg, to enable developers to build custom rendering logic.

Usage

  • Default Behavior:

    • The plugin automatically caches remote SVG files when WordPress uses get_attached_file.
  • Developer Integration:

    • Developers can extend or customize how SVGs are handled by building their own logic.
    • Use the helper function get_inline_svg($attachment_id) to fetch and render inline SVG content in themes or plugins.

Example Code

Render Inline SVG in Your Theme

<div class="icon">
    <?= get_inline_svg($attachment_id); ?>
</div>

Configuration Options

Environment Variables

SVG_CACHE_HOURS

  • Defines how long cached SVG files are stored before being refreshed.
  • Default: 72 hours.

SVG_CACHE_PATH

  • Specifies a custom directory for cached SVG files.
  • Default: wp-content/uploads/cached_svgs/.

Example .env Configuration


SVG_CACHE_PATH=/path/to/custom/cache/directory
SVG_CACHE_HOURS=72

Releases

2 releases.

Tag
Published
1.3.1 latest
Sep 23, 2025 1 year ago
1.2
Jan 2, 2025 1 year ago

These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.