getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.32k stars 168 forks source link

Asset::mediaUrl() is still broken #6273

Open jensscherbl opened 9 months ago

jensscherbl commented 9 months ago

Description

Just stumbled upon that same issue and it still doesn’t seem to be resolved in 4.1.

What I’m trying to do

I have stylesheets under /assets/styles in my setup and want to add a hash to the URL for cache busting. I know that there are two plugins available for exactly this and I also have my own workaround, but having broken features like this in the codebase leaves me with a somewhat uneasy feeling.

Expected behavior

My understanding of the Asset class from its name and description is that I can use it for all my static assets, like fonts, images, stylesheets, etc. So in my controller or template, I call asset('assets/styles/all.min.css')->mediaUrl() and (based on the name of the method) expect to get a URL (including the mediaHash) to a copy of that file in the media folder.

However, there are several issues at the moment:

Proposed solution

Not sure if this has any unwanted side effects, but my naive take on how this should work would be:

To reproduce

See description.

Your setup

Kirby Version
4.1

PHP Version
8.3

distantnative commented 3 months ago

The hard thing here is changing the behavior while keeping the breaking change small. As it is used in various places where people currently are including the assets/ part (e.g. custom Panel assets).

Cleanest way would be to use the assets root and only path the relative part to that. But this is also the one with the larger breaking change.

jensscherbl commented 3 months ago

Hey, thanks for looking into this (even though it’s only a minor issue).

Maybe it can be multiple separate fixes?

I mean, not using the configured assets-root is actually the smallest issue, so this could be another change for the longer-term.

Returning an actually working media URL, on the other hand, could be done without breaking changes, I guess?