javascript - JS脚本在CodeIgniter中的放置

标签 javascript performance codeigniter

我对 CodeIgniter 还很陌生,目前正在开发几个网站。我相信人们可能对此有不同的看法,但就原因达成普遍共识和解释会很有用。

在没有 CI 等框架的情况下进行开发时,您传统上会将各种 JS 操作(监听器、jQuery 调用等)放在页面的页脚中。

对于 CI,规范是包括一个通用的页脚和页眉,但是如果我们随后将所有页面的所有 JS 放在这个页脚中,我们就会调用每个页面上不需要的东西。

解决此问题/设置此问题的最佳方法是什么?

最佳答案

我没有任何经验,但对于我的下一个项目,我可能会尝试 Carabiner .

来自GitHub project :

Carabiner manages javascript and CSS assets. It will react differently depending on whether it is in a production or development environment. In a production environment, it will combine, minify, and cache assets. (As files are changed, new cache files will be generated.) In a development environment, it will simply include references to the original assets.

Carabiner 允许你做类似的事情

// add a js file
$this->carabiner->js('scripts.js');

// add a css file
$this->carabiner->css('reset.css');

在您的 Controller 中添加 css 或 js 文件,然后使用

在页眉或页脚中输出它们
// display css
$this->carabiner->display('css');

//display js
$this->carabiner->display('js');

我过去确实实现过类似的东西,但这个库看起来很有前途,而且比我自己构建要少得多。如果我是你,我肯定会检查一下。

关于javascript - JS脚本在CodeIgniter中的放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15273299/

相关文章:

mysql - SQLite 真的比 MySQL 快吗?

mysql - CI 3 中分页连接表的方法链接

php - 如何将 PHP 模板添加到动态生成的 Javascript 代码中

codeigniter - 修改 Codeigniter 分析器以将输出发送到数据库而不是显示在页面上

javascript - Fabricjs 按颜色隔离对象计数

javascript - 如何左对齐左 ul li 元素

c# - 我可以比较 IL 代码以确定哪种技术更快或更好吗?

javascript - 我可以在 Firefox 扩展弹出通知中设置背景颜色吗?

javascript - 在 SlickGrid 中使用 EmberJS 助手?

asp.net-mvc - Azure 上的 MVC 网站首次加载每个页面时速度非常慢