Laravel 5 正在加载旧的 css
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41160810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 is loading old css
提问by RU3
I am editing my css located in resources\assets\sass\app.css then I run gulp watch but it seems that laravel is ignoring the changes I made in my css.
我正在编辑位于 resources\assets\sass\app.css 中的 css,然后运行 gulp watch 但似乎 laravel 忽略了我在 css 中所做的更改。
I tried editing the css directly in public\css\app.css but still when I view my page in the browser the style is not working.
我尝试直接在 public\css\app.css 中编辑 css,但是当我在浏览器中查看我的页面时,样式仍然不起作用。
For example, my page's background color is white but I changed it to red, the background of my page in the browser is still white.
例如,我的页面背景颜色是白色但我将其更改为红色,我的页面在浏览器中的背景仍然是白色。
When I tried the view source in the browser and clicked on the filename in the , the background-color: #fff;
当我在浏览器中尝试查看源代码并单击 中的文件名时,背景颜色:#fff;
Hope you get my point. Do you have any idea about this?
希望你明白我的意思。你有什么想法吗?
回答by Alexey Mezenin
You should clear all cache. First, clear view cache:
您应该清除所有缓存。首先,清除视图缓存:
php artisan view:clear
php artisan cache:clear
Then clear browser cache and reload the page.
然后清除浏览器缓存并重新加载页面。
回答by Jquestions
You should use the "cache busting" feature via versioning in Laravel mix so that each new .css file saved is provisioned with a unique id. This way, every change made will force the browser to fetch the latest version of the css file. You won't even need to then hard refresh!
您应该通过 Laravel mix 中的版本控制使用“缓存破坏”功能,以便为每个保存的新 .css 文件提供一个唯一的 id。这样,每次更改都会强制浏览器获取最新版本的 css 文件。你甚至不需要硬刷新!
Really easy to implement. Just add version()
to your mix:
真的很容易实施。只需添加version()
到您的组合中:
mix.js('resources/js/app.js', 'public/js')
.version();
And then refer to your .js or .css asset using mix()
instead of asset()
.
然后使用mix()
代替.js 或 .css 资源来引用您的 .js 或 .css 资产asset()
。
<script src="{{ mix('/js/app.js') }}"></script>
If you see cache issues with your css locally, it's only going to be worse for your site users down the line who could end up seeing all sorts of issues with out of date/sync css files.
如果您在本地看到 css 的缓存问题,那么对于您的站点用户来说,情况只会更糟,他们最终可能会看到过时/同步 css 文件的各种问题。
This is the solution to this problem and everyone should use it on production env.
这是这个问题的解决方案,每个人都应该在生产环境中使用它。
回答by Udo E.
You can also use composer to refresh auto-loaded files and clear the cache. From your project root directory, run:
您还可以使用 composer 刷新自动加载的文件并清除缓存。从您的项目根目录,运行:
composer dump-autoload
and
和
composer clear-cache
this should remove your old css files
这应该删除您的旧 css 文件
回答by sklrboy
Try to make a hard refresh. Ctrl + F5on Windows I guess, on Mac it's Cmd+Shift+R.
尝试进行硬刷新。 我猜在 Windows 上是Ctrl + F5,在 Mac 上是Cmd+Shift+R。