Jump to content

Append page->modified to image URL


simonsays
 Share

Recommended Posts

Hello,

Moved this topic from "Modules". Put that there by mistake.

to avoid caching I am trying to end up with a hook to append page->modified timestamp to all image urls.

NB! I am aware of noCacheUrl method, but this one's no good as I want them to be out of cache on page update only.

NBB! I have tried CustomUploadNames module but it breaks the image path when cropping images inside the repeaters.

NBBB! Ideally it would be image->modified timestamp, which is unfortunately not updated on crop or focus.

I have come up with something like

wire()->addHookAfter('Pageimage::url', function($event) {
    $page = $event->object->get('page');
    $p = ($page instanceof RepeaterPage) ? $page->getForPage() : $page;
    $event->return = $event->return . '?nc=' . $p->modified;
});

This one has several issues though...

1) I end up with multiple appends, eg. ?nc=321223242?nc=4232424342323, etc

2) Page modified date is not updated when cropping an image (unless saving it afterwards, which is an overkill imho).

Can anyone think of a better solution for that?

 

 

 

Link to comment
Share on other sites

12 hours ago, adrian said:

Sorry for the delay in response to the CustomUploadNames issue - I am on semi-vacation, but I will try to take a look at that soon so maybe that will address your needs?

Take your time, man. You are not paid for this ?

I was just looking for a temporary solution while you fix your module.

  • Like 1
Link to comment
Share on other sites

On 10/12/2018 at 2:20 AM, simonsays said:

 

1) I end up with multiple appends, eg. ?nc=321223242?nc=4232424342323, etc

It should be easy enough to remove the first one when adding a new one by stripping off the ? and everything after it.

On 10/12/2018 at 2:20 AM, simonsays said:

2) Page modified date is not updated when cropping an image (unless saving it afterwards, which is an overkill imho).

You can hook into Pageimage::crop

Link to comment
Share on other sites

  • 2 weeks later...
On 10/12/2018 at 11:51 PM, adrian said:

It should be easy enough to remove the first one when adding a new one by stripping off the ? and everything after it.

You can hook into Pageimage::crop

Thank you very much, I'll try (been on a holiday myself).

I'd rather use your module instead, though...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...