When managing assets for a project, most of them are treated in some way before deployment. Here are some examples:
- Images are compressed and optimized for the web. JPEGs could also be converted into WEBP, PNGs can be optimized via quantization to generate huge performance wins
- scss files can be compiled and somewhat minified to reduce the load
- js files can be minified, reducing their footprint significantly
Currently, we always place these files directly in their corresponding /assets folder, for example /assets/js. Making it somewhat harder for applications to make a distinction between compiled and minified and source.
Most often, the approach I've seen is to use an addition to the extension, like /assets/js/myjs.min.js, but using something like /assets/deploy/js/my.js, or even /assets/deploy/20191125/js/my.js makes it incredibly easy to:
- Invalidate caches on CDNs, since the entire path has changed
- Rewrite the file names between staging, and production.
The code in our URL::asset function, just adds the base_url and /assets to the parameter it receives. Configuring the /assets part should be trivial, and have virtually no impact in the performance of the application, while being dead-simple to configure.
An automatically generated environments file could contain information on where the building tools placed, or should place, the built files.