Skip to content

Use assets folder to store cached assets and serve them directly#860

Merged
giuscris merged 1 commit into2.xfrom
fix/direct-assets-serving
Feb 15, 2026
Merged

Use assets folder to store cached assets and serve them directly#860
giuscris merged 1 commit into2.xfrom
fix/direct-assets-serving

Conversation

@giuscris
Copy link
Member

This pull request closes #859 by introducing changes to improve asset routing and handling, particularly for image assets. Now the generated image assets are stored in the /assets folder, allowing direct serving without php processing.

The main focus is on making the asset type explicit in routes, updating image processing paths, and preparing for future deprecations. Below are the most important changes grouped by theme:

Routing and asset handling improvements:

  • Updated the assets route in routes.php to include an optional type parameter, defaulting to images, and added a where clause to restrict valid types. This makes asset type explicit and prepares for future versions where the parameter will be required.
  • Added logic to AssetsController::asset to trigger a deprecation warning if the type parameter is missing and redirect requests to include type=images. This ensures backward compatibility while encouraging use of the new route format.
  • Modified FileUriGenerator::generate to always include the type=images parameter when generating asset URIs, ensuring consistency with the updated route structure.

Configuration updates:

  • Changed the processPath for images in system.yaml from cache/images to assets/images, aligning the configuration with the new asset management approach.

@giuscris giuscris requested a review from Copilot February 15, 2026 14:56
@giuscris giuscris self-assigned this Feb 15, 2026
@giuscris giuscris added bug Something isn't working enhancement New feature or request labels Feb 15, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Formwork’s cached image asset handling so generated images are written under /assets/images and URLs include an explicit asset type, enabling web servers to serve cached images directly (bypassing PHP) while keeping backward compatibility for legacy asset URLs.

Changes:

  • Update the assets route to support an optional {type} segment (currently constrained to images) and redirect legacy requests missing type.
  • Adjust image asset URI generation to always include type=images.
  • Move the configured processed image output directory from cache/images to assets/images, and ignore /assets/* in git.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
formwork/src/Files/FileUriGenerator.php Ensures generated asset URIs include type=images to match the new route format.
formwork/src/Controllers/AssetsController.php Adds legacy-route deprecation + permanent redirect to the typed asset route.
formwork/config/system.yaml Moves processed image output path to ${%ROOT_PATH%}/assets/images.
formwork/config/routes/routes.php Updates assets route path to include optional {type} and constrains allowed values.
.gitignore Ignores generated /assets/* content in the repository.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

public function asset(RouteParams $routeParams): Response
{
if (!$routeParams->has('type')) {
trigger_error('The "assets" route without a "type" parameter is deprecated and will be removed in a future version', E_USER_DEPRECATED);
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecation warning message doesn’t follow the existing deprecation-message convention in this codebase (most other E_USER_DEPRECATED messages include the version it was deprecated since). Consider updating the message to include the Formwork version when this route format became deprecated so it’s actionable when it appears in logs.

Suggested change
trigger_error('The "assets" route without a "type" parameter is deprecated and will be removed in a future version', E_USER_DEPRECATED);
trigger_error('The "assets" route without a "type" parameter is deprecated since Formwork 1.x and will be removed in a future version', E_USER_DEPRECATED);

Copilot uses AI. Check for mistakes.
@giuscris giuscris merged commit 41bbbbf into 2.x Feb 15, 2026
7 checks passed
@giuscris giuscris deleted the fix/direct-assets-serving branch February 15, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid using PHP to serve cached image assets

1 participant

Comments