[0.6.x] Do not inline small assets, by default #131
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
By default Vite will "inline" assets that are smaller than 4kb by base64 encoding them.
From a Laravel perspective this can cause issues for Blade apps that are looking to use the
Vite::asset()
helper on small assets.Blade specific apps could set this to
0
manually, however I also find the inconsistent behaviour as the default strange - even if it is beneficial to SPA style applications. I feel setting this to0
is a good default for Laravel, while still respecting the user configured value.The alternative would be to add some magic into the
asset
helper, but I don't think we can generally assume the file will still be in it's pre-bundled location (e.g. resources/images/pixel.png) as apps may clear that stuff out for space reasons (e.g. Serverless).Encoding at runtime also kinda sucks as well - and the inconsistency in the returned result is a little weird (plain URL vs base64 url).
I think if this is something the community wants we could add an additional function
assetOrEncoded()
or something along those lines. But I think we can punt that down the road for now.