Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom event listener for EVENT_DEFINE_URL & EVENT_DEFINE_THUMB_URL #394

Open
birdkiwi opened this issue Nov 29, 2023 · 0 comments
Open

Comments

@birdkiwi
Copy link

birdkiwi commented Nov 29, 2023

Is your feature request related to a problem? Please describe.

I would like to add get param with timestamp to every asset url, including CP, but I cannot do this in my module, because ImageOptimize rewrites urls later.

My code in the module

Event::on(
    Asset::class,
    Asset::EVENT_DEFINE_URL,
    static function (DefineAssetUrlEvent $event) {
        /** @var Asset $asset */
        $asset = $event->sender;
        $event->url = "{$event->url}?t={$asset->dateUpdated->getTimestamp()}";
    }
);

Describe the solution you would like

I would like to see my changes in urls.

Describe alternatives you have considered

Maybe we can register custom ImageOptimize events while making changes in EVENT_DEFINE_URL & EVENT_DEFINE_THUMB_URL? Let's say ImageTransformer::EVENT_DEFINE_URL & ImageTransformer::EVENT_DEFINE_THUMB_URL

Additional context

Initial problem is that we have cache age set to one year in Amazon S3 storage. Once client "replace file" asset with the same filename through CP, browser cache keeps showing the previous file until manually refreshing browser cache. I decided to add dateUpdated timestamp to the end of the URL so it will not show cached version once replaced. But I have a problem described above. Maybe you can suggest another better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant