lonnieezell / Bonfire2

CodeIgniter 4-based application skeleton
MIT License
132 stars 50 forks source link

More flexible asset naming? #408

Closed dgvirtual closed 6 months ago

dgvirtual commented 11 months ago

I was thinking about improving asset functionality, but would like to discuss the proper solution first.

Currently only assets with a single dot in filename are processed correctly (which is undocumented, by the way). So,

bootstrap.bundle.min.js name would be incorrectly interpreted as bootstrap.js and assets controller would search for such a file (and fail to find it). Both "bundle" and "min" would be ignored by the controller, which presumes that anything between the first and last segments is the version/timestamp.

I would like to improve the assets system so that the timestamp/version would be injected into the filename as the last segment before the .extension, preceeded not by a dot, but by a special separator, like: bootstrap.bundle.min__1704487405.js or bootstrap.bundle.min__1.5.js (if the separator is __) or bootstrap.bundle.min~1704487405.js or bootstrap.bundle.min~1.5.js (if the separator is ~).

The user would be allowed to define his own separator in the config file (with a suggestion to use any web-safe character or character combination, while the default could be ~ or double underscore __ or something else never found in asset file names).

That way the assets helper would only need to inject separator and timestamp/version, and the controller would have to remove separator and timestamp/version before determining the file to serve (and separator, coupled with the dot before the extension, would mark clear boundaries of what to remove). That way we can avoid converting the file name into array and guessing what the last segment before the extension is.

How does that sound?

kgrruz commented 11 months ago

Looks great. I stumbled upon this a while ago. I decided to just rename the files.

lonnieezell commented 11 months ago

I think that sounds great.

dgvirtual commented 11 months ago

Thanks for positive response. I have tested the changes and submitted a PR. The PHPstan and PHPunit errors seem to be not mine this time.