VOOZH about

URL: https://deepwiki.com/calevans/staticforge/8.5-deployment-and-optimization-features

⇱ Deployment & Optimization Features | calevans/staticforge | DeepWiki


Loading...
Last indexed: 11 February 2026 (5f6a2a)
Menu

Deployment & Optimization Features

This document covers StaticForge's deployment and optimization features that prepare sites for production environments. These features handle cache busting, asset optimization, and intelligent file synchronization to remote servers.

For information about generating sitemaps and RSS feeds, see SEO & Discovery Features. For content rendering and processing, see Content Renderers.


Overview

StaticForge includes three core deployment and optimization features:

FeaturePurposeEvent PhasePriority
CacheBusterGenerates unique build identifiers for cache invalidationCREATE10
TemplateAssetsCopies template CSS/JS to output directoryPOST_LOOP100
Upload SystemIntelligent SFTP sync with incremental updatesUPLOAD_CHECK_FILEN/A

These features work together to ensure production deployments are optimized, cacheable, and efficiently synchronized.

Sources:


CacheBuster Feature

The CacheBuster feature generates a unique build identifier that enables browser cache invalidation when content changes. It runs during the CREATE event at the highest priority (10) to ensure the build ID is available to all subsequent features.

Architecture


Sources:

Implementation Details

The CacheBuster feature consists of two main components:

Feature Class

The Feature class registers a single event listener for the CREATE event:


The handleCreate() method executes at priority 10 (very early) to ensure the build ID is available during the entire generation pipeline.

Sources:

CacheBusterService

The service generates a unique build identifier using a timestamp:


This timestamp-based approach ensures:

  • Each build has a unique ID
  • The ID is consistent for all files in a single build
  • Browser caches are invalidated when content changes

Sources:

Container Variables

The feature sets two variables in the Container:

VariableFormatExampleUsage
build_idTimestamp string1704067200Direct timestamp access
cache_busterQuery parametersfcb=1704067200Template asset URLs

Sources:

Template Integration

Templates access the cache buster variable to append query parameters to asset URLs:


This ensures browsers fetch fresh assets after each deployment while allowing aggressive caching between deployments.

Sources:

Event Lifecycle


Sources:


TemplateAssets Feature

The TemplateAssets feature copies CSS, JavaScript, and image files from template directories to the output directory during the POST_LOOP event. This ensures template-specific assets are available in the generated site.

Execution Phase

TemplateAssets runs at priority 100 in the POST_LOOP event, after all content has been rendered but before deployment:


Sources:

Asset Directory Structure

Templates organize assets in a standard structure:

templates/
└── {TEMPLATE_NAME}/
 ├── assets/
 │ ├── css/
 │ │ └── style.css
 │ ├── js/
 │ │ └── main.js
 │ └── images/
 │ └── logo.png
 └── *.html.twig

TemplateAssets copies the entire assets/ directory to:

output/
└── assets/
 ├── css/
 │ └── style.css
 ├── js/
 │ └── main.js
 └── images/
 └── logo.png

Sources:

Integration with AssetManager

The AssetManager system (documented in Asset Management) allows features to register additional CSS and JavaScript files dynamically. TemplateAssets complements this by ensuring template-specific static assets are available.

Sources:


Upload System

The upload system provides intelligent SFTP synchronization with incremental updates, hash-based change detection, and plugin extensibility through the UPLOAD_CHECK_FILE event.

Upload Pipeline Architecture


Sources:

Manifest-Based Synchronization

The upload system maintains a staticforge-manifest.json file on the remote server containing SHA-256 hashes of all deployed files:


This manifest enables:

  • Incremental uploads: Only changed files are transferred
  • Deletion detection: Files removed locally are deleted remotely
  • Hash verification: Ensures file integrity

Sources:

Smart Hashing Algorithm

The upload system implements intelligent hash calculation for text files:


For text files (HTML, CSS, JavaScript), the system strips cache buster parameters (?sfcb=...) before hashing. This prevents unnecessary uploads when only the build ID changed but content remains identical.

Sources:

UPLOAD_CHECK_FILE Event

The UPLOAD_CHECK_FILE event fires for each file before SFTP upload, allowing plugins to intercept and handle uploads differently:

Event Data Structure


Event Control Flags

FlagTypePurpose
handledbooleanSet to true if plugin uploaded the file (e.g., to S3)
skip_uploadbooleanSet to true to skip SFTP upload entirely
should_uploadbooleanSet to true to force upload even if hashes match

Sources:

SFTP Configuration

The upload system requires SFTP credentials in .env:










































VariableRequiredPurpose
UPLOAD_URLYesPublic URL for production site
SFTP_HOSTYesSFTP server hostname or IP
SFTP_PORTNoSFTP port (default: 22)
SFTP_USERNAMEYesSFTP authentication username
SFTP_PASSWORDYesSFTP authentication password
SFTP_REMOTE_PATHYesRemote directory path for uploads

Sources:

Upload Command Integration

The site:upload command orchestrates the entire upload pipeline:


Sources:


Deployment Workflow

This section demonstrates how CacheBuster, TemplateAssets, and the Upload system work together in a complete deployment workflow.

Build and Deploy Sequence


Sources:

Cache Invalidation Strategy

The CacheBuster ensures browsers fetch updated content after deployment:

DeploymentBuild IDAsset URLBrowser Behavior
Initial1704067200/css/style.css?sfcb=1704067200Fetch from server, cache
No Changes1704067200/css/style.css?sfcb=1704067200Use cached version
After Update1704070800/css/style.css?sfcb=1704070800Cache miss, fetch from server

This approach provides:

  • Aggressive caching: Assets cache indefinitely between deployments
  • Instant invalidation: Build ID change forces cache refresh
  • Efficient uploads: Smart hashing prevents unnecessary file transfers

Sources:


RenderSiteCommand Options

The site:render command provides several options for deployment preparation:

Clean Option

The --clean flag removes all files from the output directory before generation:


This ensures:

  • No orphaned files from previous builds
  • Clean state for each generation
  • Predictable output directory contents

Sources:

Directory Overrides

The command supports runtime directory overrides:


These options enable:

  • Multiple content sources
  • Different output locations for staging/production
  • Custom build pipelines

Sources:

Template Override

The --template option allows runtime template selection:


This enables:

  • Testing different templates without modifying .env
  • Environment-specific template selection
  • A/B testing different designs

Sources:


Configuration Reference

Environment Variables

Deployment and optimization features use the following configuration:


Sources:

Feature Configuration

Deployment features do not require configuration in siteconfig.yaml as they use sensible defaults. However, they can be disabled if needed:


Sources:


Best Practices

Cache Busting

  • Always use {{ cache_buster }} in template asset URLs
  • Apply to all static assets: CSS, JavaScript, images referenced in templates
  • Test cache invalidation: Verify browsers fetch new assets after deployment

Asset Management

  • Organize template assets in standard assets/ directory structure
  • Minimize asset size: Optimize images and minify CSS/JavaScript before deploying
  • Use relative paths within CSS for intra-asset references

Upload Optimization

  • Review .gitignore: Ensure .env is excluded from version control
  • Test uploads to staging: Validate SFTP credentials before production deployment
  • Monitor manifest sync: Check logs for hash comparison results
  • Use secure credentials: Store SFTP passwords securely, consider SSH keys

Sources:


Troubleshooting

Cache Buster Not Applied

Symptom: Asset URLs lack ?sfcb= parameter

Causes:

  • Template missing {{ cache_buster }} variable
  • CacheBuster feature disabled

Solution: Add cache buster to template asset URLs:


Assets Not Copying

Symptom: Template CSS/JS missing from output directory

Causes:

  • TemplateAssets feature disabled
  • Template assets directory missing or misnamed
  • Output directory permissions issue

Solution: Verify template structure includes assets/ directory and check file permissions

Upload Failures

Symptom: site:upload command fails with connection errors

Causes:

  • Incorrect SFTP credentials in .env
  • Firewall blocking SFTP port
  • Remote path does not exist

Solution: Verify SFTP configuration and test connection manually:


Sources:

Refresh this wiki

On this page