Search…

X3 Photo Gallery Support Forums

Search…
 
trpgforum
Experienced
Topic Author
Posts: 105
Joined: 05 Jul 2019, 03:40

Update when re-uploading the same image

23 Jan 2024, 04:19

Hello Karl

I have been having a problem for years that we have already discussed in a similar context in this forum:

On company websites it often happens that, for example, you upload print screens of software solutions to a gallery. The name of the image corresponds to the name for the mask, e.g. “Address form”. The image then appears in the gallery without any further work after the initial upload and the caption “address form” underneath. It's so great!

Now maybe change this address form in the software. I create the print screen again under the same name and upload it. And there it simply never appears currently unless I rename the image. You can probably imagine how troublesome this can be if you have this case again and again. The image name also changes.

The problem also occurs when I only see later in the gallery that out of 200 images, 15 have sensor spots in them. When I then regenerate these images (the image name must remain unchanged because it is also the order number) I always have enormous problems and waste an incredible amount of time. Unfortunately, deleting the old image versions beforehand doesn't help. Just like clearing browser cache.

Couldn't this problem be solved finally and cleanly with a function or, even better, if old disturbing data is definitely deleted or overwritten when uploading?

Maybe I'm stupid. But this problem must be solvable somehow. I think it's really the only thing that's been getting on my last nerve for years. Well, maybe that's an exaggeration. I still have two or even three nerves ;-)

Best regards from Basel
Thomas
THOMAS RUF PHOTOGRAPHY
Landscape - Nature - Macro
4132 Muttenz
Switzerland
www.thomas-ruf.ch
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13998
Joined: 30 Sep 2006, 03:37

Re: Update when re-uploading the same image

23 Jan 2024, 23:21

Some good points, but first of all, let me explain exactly what the problem is and why it can't be solved by some of your other suggestions.

What is the problem?
The problem is your browser cache, and potentially CDN cache (for example if you are using Cloudflare). There is nothing in X3 that is "keeping" the old image, and there is nothing we can "delete" up front or anything. All the data is on the server is 100% correct, but your browser decides to output old images from it's cache.

For example, you have an image at the following path (relative to domain):
/folder/path/image.jpg

The you replace that image with a NEW image, the path remains the same:
/folder/path/image.jpg

When that image is requested in browser, your browser then goes "Hey, I have that path already cached, and I was instructed to cache this image for 1 year, therefore I will serve the cached image from browser". The old image is then served from browser.

How is this solved in modern web design?
Because cache is important, in modern web design, all platforms use a renaming scheme to update static assets like images, CSS and Javascript. This is the only proper way to make sure you always serve fresh assets when assets are updated.

How do other platforms solve this?
Most other platforms, for example Google, Flickr or other database-based image galleries, have images locked to a database, and will always use hash-based names for images once they are uploaded. Try downloading an image from Facebook, Flickr or Google, and the name will be something like 5698040331133625348_n.jpg (often longer). When/if the image changes, the ID will change also ... Any "title" or "caption" for the image, is entirely separated from the image.

In X3, you keep the real file names, but if you then want to avoid caching issues, you would yourself need to increment the filename ... For example if you had "image.jpg", delete it and upload "image-A.jpg". If you don't like the "name", then why not use titles/captions instead? You can't rely on a fixed image name, especially if you intend to update the image.

Disable cache?
Another option would be to entirely disable cache headers on your server, but this is very unproductive. This means static assets (like images) will never cache in browser or on CDN, and will ultimately make your website slower.
trpgforum wrote:Couldn't this problem be solved finally and cleanly with a function or, even better, if old disturbing data is definitely deleted or overwritten when uploading?
As you may understand from the above, all old data is definitely 100% deleted and 100% overwritten. This is not the problem. The problem is that when your browser makes a request to a path/to/image.jpg that it has requested earlier, this path is cached in browser. It's not in X3, but your browser, and X3 can't delete cache in your browser.

Just for clarity, if you made your own website (not X3), and did the same (replace an image with another image with the same name), the exact same thing would happen. This is not an X3-specific issue, and I wouldn't write this long a post if there was an obvious solution. It's the way of the modern web.

Solutions
  1. Rename the new image incrementally when you update. This would be the recommended solution, if you posted this question in some web developer forum.
  2. Disable image cache headers on server. This would basically tell browsers to NOT cache any images, and would therefore always load the latest/newest image updated on server. This not a recommended solution, because caching is an important feature of web performance. It would always load images from your server, instead of using cache, even for images that never change in 10 years.
  3. There could be a solution in X3, where I include the image's server date in URL, for example "path/to/image.jpg?1706069910" ... The date (epoch time) would change when the image gets updated on server, and would therefore force the browser to refresh, because the path changes. This could be a solution, although it is considered a bit of a "hack".
I may very well implement solution #3 in a future release.
 
trpgforum
Experienced
Topic Author
Posts: 105
Joined: 05 Jul 2019, 03:40

Re: Update when re-uploading the same image

24 Jan 2024, 02:42

Thank you very much Karl! 

You have explained it very well! Until now I wrongly assumed that the updating problem only affected images that were inserted directly as image links in the text. Now I have finally understood why this is also the case in galleries! 

In my opinion, it would be a very simple and practical solution if the user could optionally choose to add the date and time version to all imported images when uploading, e.g. "---20240124_0833". The automatic image labelling would then only have to use the part of the image data name to the left of "---".

It would perhaps be even better if there was a function that I could call up per gallery using a button in order to attach the current version to all or selected images as described above. Then you wouldn't burden users who don't need this function. But for purposes like the one I listed, it would be incredibly time-saving!

Thanks again for your great support!

Best regards
Thomas
THOMAS RUF PHOTOGRAPHY
Landscape - Nature - Macro
4132 Muttenz
Switzerland
www.thomas-ruf.ch
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13998
Joined: 30 Sep 2006, 03:37

Re: Update when re-uploading the same image

24 Jan 2024, 21:37

trpgforum wrote:You have explained it very well! Until now I wrongly assumed that the updating problem only affected images that were inserted directly as image links in the text.
It's easier to resolve images inserted into the content ... In the path "{{path}}antarctica.jpg" you can just increment a parameter "{{path}}antarctica.jpg?v=2" etc. Of course, it's not simple to maintain, because after updating an image (with the same name), you would also need to update the "?v=2" to "?v=3" etc.
trpgforum wrote:In my opinion, it would be a very simple and practical solution if the user could optionally choose to add the date and time version to all imported images when uploading, e.g. "---20240124_0833". The automatic image labelling would then only have to use the part of the image data name to the left of "---".
I'm actually not sure what you mean by this. First of all, if the system is renaming your images, it will be difficult to track all your images after upload, since they will have different names. Second, if you have an image myimage---20240124_0833.jpg, each time you upload a new version, you will have new names myimage---20240125_1133.jpg etc ... You will end up with multiple duplicate images with multiple names:

myimage---20240124_0833.jpg
myimage---20240125_1233.jpg
myimage---20240125_1533.jpg

How will you manage the images? You will then need to locate and delete the older versions after each upload. Furthermore, if you already added "myimage---20240124_0833.jpg" into the content, and then want to update it manually to "myimage---20240125_1233.jpg", you will then need to edit this manually. Surely you must agree this will be very clumsy?

I don't see how this would be effective. Then why not instead simply rename the image yourself after upload? Then you don't need to delete orphan outdated files. Or even better, my suggestion about auto-appending myimage.jpg?DATE parameter into the images in galleries. This would resolve cache issues, without having to deal with multiple versions of the same image.
trpgforum wrote:It would perhaps be even better if there was a function that I could call up per gallery using a button in order to attach the current version to all or selected images as described above.
In X3, there is no such thing as "the current version". The current version is always the newest version. It's your browser that may serve an old version. If you are thinking of your suggestion about auto-naming images on upload, that won't work, because how is X3 supposed to store "different versions" of the same image, and how is it supposed to know what versions belong together? All versions you upload will be visible in the gallery.
trpgforum wrote:But for purposes like the one I listed, it would be incredibly time-saving!
I strongly disagree. You will end up with multiple images with long names. How will this help?
 
trpgforum
Experienced
Topic Author
Posts: 105
Joined: 05 Jul 2019, 03:40

Re: Update when re-uploading the same image

25 Jan 2024, 02:08

Hello Karl

Thank you for your understandable and helpful argumentation! 

If you can automatically add a date parameter when uploading to galleries, that would be the solution. It is important to also include the time in the date, as this is the only way to correct errors found in an image by re-uploading the corrected image file of the same name a few minutes later without having to wait a day...

For an image that I insert in an image link in the content, I can live with the parameter ?v=1,2,3 etc. that I enter myself, just as you answered one of my earlier questions.

Best regards
Thomas
THOMAS RUF PHOTOGRAPHY
Landscape - Nature - Macro
4132 Muttenz
Switzerland
www.thomas-ruf.ch
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13998
Joined: 30 Sep 2006, 03:37

Re: Update when re-uploading the same image

25 Jan 2024, 04:49

trpgforum wrote:If you can automatically add a date parameter when uploading to galleries, that would be the solution. It is important to also include the time in the date, as this is the only way to correct errors found in an image by re-uploading the corrected image file of the same name a few minutes later without having to wait a day...
Yes, but let me explain again ... Nothing happens specifically on upload. However, in the html output for your gallery, I can include image.jpg?DATE, and the DATE will come from the SERVER create date (the date the file was created on disk). Then, when you upload a new version overwriting the current version, the file DATE on server will change, and the image.jpg?DATE will change also, which will therefore prevent browser cache from serving the old version.

This is an idea, and it is something I can look into for next release, which currently is a while away since I am working on Files Gallery.
 
trpgforum
Experienced
Topic Author
Posts: 105
Joined: 05 Jul 2019, 03:40

Re: Update when re-uploading the same image

25 Jan 2024, 07:40

This solution would of course be perfect! That would really solve any re-upload issues. And will save an incredible amount of time...
THOMAS RUF PHOTOGRAPHY
Landscape - Nature - Macro
4132 Muttenz
Switzerland
www.thomas-ruf.ch