AssetCompress v0.17 available
Earlier today, I packaged up AssetCompress 0.17. This release has a few noteworthy features.
Cached builds in development
Historically, in development every build file would be rebuilt on every request even if the source files did not change. While this works OK if you have a few build targets, it can get pretty slow if you have many build targets, big build targets or use a pre-processor like sass. As of 0.17, build targets will be cached until their source files change. This means you should see noticeable performance improvements when you are not changing your assets.
The cache files can be cleared using Console/cake asset_compress.asset_compress clear
like any other build output.
Inline assets
While AssetCompress has always been really good as converting multiple source files into a single external resource, it has not been able to inline those assets into the source page. Inlining assets is useful when you have small assets, or assets where you want to avoid the additional HTTP call for. In 0.17 you can use inline assets with inlineCss()
or inlineScript()
:
echo $this->AssetCompress->inlineCss('layout.css'); echo $this->AssetCompress->inlineScript('bootstrap.js');
A big thanks to ‘coryjthompson’ for contributing this feature.
Other plugin updates
In other news, I’ve also started work on AssetCompress for CakePHP 3.0 . The plugin is already in a working pre-release state, and is installable via composer. There have been a few breaking changes so far:
- Dynamic build files and all features related to them have been removed. Dynamic build files presented a few challenges around maintenance and went against my goals of creating a fast and simple way to integrate all your asset pipeline features into one plugin.
- Prefixes on build files have been removed. In previous versions if you
started a build file with
js_
orcss_
, these prefixes would be removed and used as the file suffix. You must now always include the file extension in the build target
As always, let me know if you run into any issues with AssetCompress by opening an issue .
I am trying to use a plug-in for cakephp 3. But it does not work because there is no class AssetKompressor (see screenshot: http://dl2.joxi.net/drive/0001/1278/79102/150707/7bd4d995d9.jpg). Please help!
Igor on 7/7/15
Igor: You’ll have to make sure that the plugin is both installed and loaded with @Plugin::load(‘AssetCompress’)@.
mark story on 7/10/15
I use CakePHP since version 1.3. What do you recommend I certainly did. But it does not help. The plugin is not working.
Igor on 7/19/15
Hi Mark, thanks for your time that you put into developing this plugin. I am using CakePHP 2.8 and i am scratching my head on few issues. I have read in and out the Wiki but i was unable to figure out how to integrate Uglifyjs?
sphereweb on 3/7/16
My UglifyJs section in the asset_compress.ini, using Windows:
[filter_UglifyJs]
node = C:\Program Files\nodejs\node.exe
node_path = C:\Users\cosmin\AppData\Roaming\npm\node_modules
uglify = C:\Users\cosmin\AppData\Roaming\npm\node_modules\uglify-js\bin\uglifyjs
Is this correct? It is not very clear in your wiki.. could you let me know what i have wrong?
sphereweb on 3/9/16
How to install Uglifyjs and CssMin Filter using composer (CakePHP 3). In the documentation there is an explanation for JsMin filter which is no longer used.
Zoran on 3/28/16