CakePHP 2.1 Asset Compress Plugin not creating cached files
Asked Answered
E

3

7

I'm using the CakePHP Plugin AssetCompress (v 0.7) which works fine, except that it doesn't cache any files in the directory. This is my asset_compress.ini setup:

[General]
writeCache = true
cacheConfig = false
alwaysEnableController = true
debug = false

[js]
timestamp = true
paths[] = WEBROOT/js/
cachePath = WEBROOT/cache_js/

[speedtest.min.js]
files[] = speedtest/speedtest.js

Additional notes:

  • I set debug to "0" in core.php
  • the cache_js folder is writeable (777)
  • also I'm using MemCache as a caching engine (not sure if this might cause the issue)

Has anybody experienced the same issue with the Asset Compress plugin?


Update: This is what I use for the CSS/Less part, works pretty well: https://github.com/Hyra/less

Eyas answered 6/5, 2012 at 10:46 Comment(7)
What does your layout look like? Also have you tried the shell to see if you can manually build them? $ cake asset_compress.asset_compress buildEthnomusicology
Sadly I don't have access to the shell :( Not sure what you mean by "what does your layout look like". AssetCompress works perfectly fine (combining and minifying scripts) the only issue I have is that the files are not stored after they are created (even though I gave the appropriate permissions)Eyas
Static files are only generated using the shell, so I don't know how you are going to accomplish it if you don't have access. I would guess building them on your local PC using the shell and then uploading the generated static files along with app/tmp/asset_compress_build_time may work.Tolerance
Are you sure? Why can't this plugin create static files without using the shell? This would explain why I cant find the static files.Eyas
Have you tried the "Working with dynamic build file" way ?Heyde
@J-P "Dynamic build files will only work through the controller while debug > 0. Before deploying you should run the shell to generate static assets." Christian Strang according to that, I would say I'm pretty sure. You can confirm by opening a ticket on github or going on IRC and asking markstory yourself. The reason you cant without shell: "When debug = 0, the plugin ignores request to generate assets. This is a security feature to prevent malicious users from using expensive resource processing as a way to cause a DOS attack. You can use the Shell to generate build files at any time."Tolerance
Another way could be a special function you put in a controller and in the beforeFilter, if the special action is called, you turn debug to 2, and in the afterFilter, you turn it back to 0. That's kind of hack in some way but it would do the trick and you can always make the acess to that special action restricted based on Auth or even IP Address if DDOS is really a concern.Heyde
L
2

If I understand well this Github's wiki page you should change cacheConfig = false to cacheConfig = true to take advantage of MemCache.

Lashondalashonde answered 9/5, 2012 at 7:35 Comment(4)
Mhh... interesting. I deactivated MemCache and kept the cacheConfig setting = false but still the files weren't stored in the cache_js folder. Then I activated "FILE" as a caching mechanism but still the created Javascript file is not stored in the cache_js folder (I also checked the cache folder but still no luck).Eyas
By any chance, does the log file hold any meaningful information related to your problem (app/tmp/logs/error.log)Heyde
also what filters are you using ? If your asset_compress.ini is complete up here, It's obvious to me that it won't work. In my understanding of this plugin, you need to tell him what filter(s) to use with your files, such as Uglify.js or YUICompressor. I would recommend going through the asset_compressor's wiki to configure it right.Heyde
you don't have to use filters afaikTolerance
V
2

You have to generate the files using the shell script. The files are not automatically generated.

https://github.com/markstory/asset_compress/wiki/Shell

Violinist answered 3/11, 2012 at 0:2 Comment(0)
O
1

To generate and store static assets defined in the asset_compress.ini config or through the AssetCompress helper on the fly. This is to save you having to manually run the console script everytime you change you css or js files.

This is what some will define as a "nasty" hack, I call it a working solution. It simply runs the console script via the php exec() method every time the AppController beforeFilter() runs and the debug level is greater than 0. So in production where your debug level should be 0, the exec() won't be run.

Add the following to your /app/Controller/AppController.php beforeFilter() function.

if(Configure::read('debug') > 0){
  exec(APP.'Console'.DS.'cake -app '.APP.' AssetCompress.asset_compress build -f');
}

This is assuming that you can run the normal AssetCompress from the console (linux) or cmd prompt (windows)

Onehorse answered 23/10, 2013 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.