📅  最后修改于: 2023-12-03 14:43:45.172000             🧑  作者: Mango
Laravel envasset_url is a helper function in Laravel that provides a way to add a version number to the assets URL based on the version of the application. It is an extension of the asset()
helper function that is commonly used to link CSS, JavaScript, and other files in Laravel.
To use the envasset_url()
function, first, set the APP_VERSION
variable in your .env
file.
APP_VERSION=1.0.0
Then, use the envasset_url()
helper function instead of the asset()
function when linking to your assets. The version number defined in APP_VERSION
will be automatically appended to the asset URL.
<link href="{{ envasset_url('css/main.css') }}" rel="stylesheet">
This will generate a URL like https://example.com/css/main.css?v=1.0.0
.
By adding a version number to the assets URL, browsers will download the latest version of the file if it has changed. This helps to avoid caching issues and ensures that your users always see the latest version of your assets.
This feature is also useful in deployment scenarios where you may need to force clients to download new assets without forcing them to clear their browser cache.
In conclusion, Laravel envasset_url is a simple and powerful tool for managing versioned assets in your Laravel application. With easy setup and usage, you can ensure that your assets are always up-to-date and avoid the unnecessary caching issues that can arise when updating your files.