[英]Laravel css and js not loading in on the first page
I can't figure out why my css and js doesn't load.我不知道为什么我的 css 和 js 无法加载。 I am using node and rand the npm install and npm run dec commads multiple times and also tried writing the paths like this:我正在使用节点和 rand npm 安装和 npm 多次运行 dec commads 并尝试编写如下路径:
<!-- Styles -->
<link rel="stylesheet" href="{{ asset('public/css/app.css') }}">
<!-- Scripts -->
<script src="{{ asset('public/js/app.js') }}" defer></script>
and like this:像这样:
<!-- Styles -->
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
And still my page looks like this:我的页面仍然是这样的:
This is my main paige that loads up first when you enter the site.这是我进入网站时首先加载的主要页面。 When i go into the "view page source" and click on the links for the css and js files it returns a 404 page.当我 go 进入“查看页面源代码”并单击 css 和 js 文件的链接时,它会返回 404 页面。 All the other pages i have are experiencing the same issue.我拥有的所有其他页面都遇到了同样的问题。
Your asset url should point to your /public path.您的资产 url 应该指向您的 /public 路径。 Use asset('css/app.css')
and asset('js/app.js')
.使用asset('css/app.css')
和asset('js/app.js')
。 You can configure the asset url by setting the ASSET_URL variable in your.env file.您可以通过在 your.env 文件中设置ASSET_URL变量来配置资产 url。
Don't forget your rewrite rules.不要忘记你的重写规则。 Something like...就像是...
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.