Skip to content

Conversation

kevinmeijer97
Copy link
Member

This PR changes the way images are served to the browser. Images are now delivered via routes, allowing them to be generated on-demand rather than during the initial page load. This approach improves overall page loading times.

The routes used for the srcset are structured as follows:
storage/glide-image/{preset}/{fit}/{signature}/{file}{format}
For example:
storage/glide-image/2xl/contain/f26f2e8e2d900e81b91bb236a451a196/assets/bierbekers-bedrukken-1685894250.jpg.webp
The signature is generated based on the asset path and the provided parameters.

Glide still handles the image generation itself, so the underlying generation behavior remains unchanged. Generated images are stored in the public folder, for example:
/img/containers/assets/xxx.jpg/1a5520e23a7f46fcc39e1e75c2c840f0/xxx.webp

BobWez98
BobWez98 previously approved these changes May 1, 2025
@indykoning
Copy link
Member

Glide still handles the image generation itself, so the underlying generation behavior remains unchanged. Generated images are stored in the public folder, for example:
/img/containers/assets/xxx.jpg/1a5520e23a7f46fcc39e1e75c2c840f0/xxx.webp

Can we do something about this so it stores it to the exact path we've requested, this way images on the page won't constantly have to go through php and Laravel once the image has been generated

@BobWez98
Copy link
Collaborator

BobWez98 commented May 1, 2025

Why not use the path of where the file is stored as route? Then if there is a file at for example /img/containers/assets/xxx.jpg/1a5520e23a7f46fcc39e1e75c2c840f0/xxx.webp it will just return that instead of having to go through the PHP to get the file.

I meant to press request changes but i misclicked 😛

@kevinmeijer97
Copy link
Member Author

The resized images are now saved at the same path as their corresponding route.

Updated route structure:
img/storage/glide-image/{preset}/{fit}/{signature}/{file}{format}

For example, a resized image would now be stored at:
public/img/storage/glide-image/4xl/contain/44d8a88f61edef3b46a32e98514925c8/assets/example/example-image.png.webp

This approach maintains compatibility with Statamic's cache_path configuration (set to 'public/img'), while providing a more consistent storage pattern.

BobWez98
BobWez98 previously approved these changes May 16, 2025
BobWez98
BobWez98 previously approved these changes Jun 11, 2025
Comment on lines 30 to 31
$asset = AssetFacade::findByUrl(Str::start($file, '/'));
$this->asset = $asset;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can directly set $this->asset here, i think the typehint in the comment is not needed then too

/** @var ?Asset $asset */
$asset = AssetFacade::findByUrl(Str::start($file, '/'));
$this->asset = $asset;
$this->params = ['s' => $signature, 'preset' => $preset, 'fit' => $fit, 'format' => $format];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe after merge; We can create a ImageRequest to validate the parameters, now it will probably have an empty string in one of these variables if not filled.

Copy link
Member Author

Choose a reason for hiding this comment

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

If one of these parameters is not filled it means the given path is not right, which already results in a 404.
Haven't been able to get this to go wrong at least.

@royduin royduin merged commit be6edaa into master Jul 29, 2025
12 checks passed
@royduin royduin deleted the feature/resizer-refactor branch July 29, 2025 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants