Jump to content
simonsays

Append page->modified to image URL

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?

 

 

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...