SEO-friendly image URLs

Hi @all!
Is there a way in Grav to make the image URLs more SEO-friendly?
Currently the generated URLs look somewhat like “src=”/grav/images/c/1/e/d/b/c1edbe4be099530736c1e9ec39be7f52ef941a54- mock1x.png"

Ideally the img would be in the same directory, as the containing webpage (e.g. “/products/mock1x.png”); and also would not have any hash in the URL.

Thanks a lot for any suggestions!

1 Like

If you were to not cache them, but access them directly, they would appear as you expect.

Could & should I use Grav in production without caching?
And could I even disable image caching? Grav docs state:

Image caching is also always on

Images are only cached when necessary, that is, when an action is applied to it by Grav. For example, with a file named unsplash_1.jpg in the user/pages/01.home/-folder:

user/themes/antimatter/default.html.twig

{{ page.media['unsplash_1.jpg'].display('thumbnail').sepia().html() }}
{{ page.content }}

user/pages/01.home/default.md

...
# Grav is Running!
## You have installed **Grav** successfully

![Unsplash](unsplash_1.jpg)

Congratulations!
...

In the first line of code in the template, we are making the image sepia-toned. This is done dynamically by Grav, so it must be cached to retain it’s changed appearance, and results in a path like:

http://temp.dev/images/1/b/5/1/a/1b51a1da4b76fc16dfc4c83f31ef3252abc35a05-unsplash1.jpeg

However, in the page’s content, we are accessing the image directly (which we could also do in a template, by not adding any effects) and thus there is no reason for Grav to cache it. This results in a regular path:

http://temp.dev/user/pages/01.home/unsplash_1.jpg

So if you want to ensure SEO-friendly URLs, you’d need to do the processing yourself outside of Grav. I could imagine a system wherein the cache generates differently named URLs, exactly replicating paths from the user/pages/ structure, but it would potentially have to account for a variety of different configurations, which is why the current cache-mechanism is rather more fail-safe.

1 Like