[英]laravel js best practice
I'm writing a Laravel 5.3 app using it's default layout, and I'm wondering which is the best practice for adding an external js library. 我正在使用它的默认布局编写一个Laravel 5.3应用程序,我想知道哪个是添加外部js库的最佳实践。
Should I have to put the js file directly in public/js, or there is another cleaner way to do it? 我是否应该将js文件直接放在public / js中,还是有另一种更简洁的方法呢?
我通常在public / js中添加我的外部库,比如jQuery,因为在我的视图布局中使用它更自然,因为Laravel隐式引用了这些资产的公共目录。
One way to do this is- 一种方法是 -
Directory structure 目录结构
Public
|
|-js
|-script.js
|-css
|-style.css
To call libraries call asset()
helper 要调用库,请调用asset()
帮助程序
<script src="{{ asset('/js/script.js') }}"></script>
I also put everything is the public directory public/js etc, but sometimes I create sub directories to keep thing easy and orderly. 我还把所有东西都是公共目录public / js等,但有时我创建子目录以保持简单有序。 Then you can call 然后你可以打电话
asset('js/widgets/mywidget.js').
I do a similar thing with css and siteicons. 我用css和siteicons做了类似的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.