0

I'm looking for a way to organise my js and css libraries in CakePHP 2.4.1, but I cannot seem to find the best way to do it.

In my layout.ctp is a section where all js and css libraries are included. However all libraries are loaded on every page while only some should be loaded per page.

I could define the required libraries in the corresponding controller, but I don't think this is a good MVC practice.

Hope to hear some good advice.

4

2 回答 2

0

您可以直接在视图文件中按需加载脚本和 css。

这样,您只会在布局中加载视图所需的脚本和/或 css。

如文档中所述:使用脚本和 css 文件的块

于 2013-10-14T22:23:48.337 回答
0

这取决于你有多少 js / css。如果数量不是很大,您应该将所有 js/css 连接/缩小到一个文件中,并将其包含在每个页面上。我为此使用Codekit。Mark Story 的资产压缩插件显然也不错,虽然我没用过。

缩小的 JS / CSS 非常小。

于 2013-10-14T22:02:45.183 回答