Giter VIP home page Giter VIP logo

asset_compress's Introduction

Asset Compress

Build Status codecov.io Total Downloads License

Asset Compress is CakePHP plugin for helping reduce the number of requests, and optimizing the remaining requests your application makes for Javascript and CSS files.

Features

  • Development mode builder that rebuilds assets on each request.
  • Command line build tool to compile static assets for deployment.
  • Built-in support for LESScss, Sass and CoffeeScript, as well as several minifiers.
  • Powerful and flexible filter system allowing you to add your own minifiers/pre-processors.
  • Simple configuration file.
  • Incremental builds that don't recompile assets when they don't need to be.

Installing

Add this plugin to your application with composer:

php composer.phar require markstory/asset_compress

Then make sure you load the plugin:

// in src/Application.php
// in the bootstrap() method add
$this->addPlugin('AssetCompress');

Copy the config/asset_compress.sample.ini from the plugin to your app's config/asset_compress.ini. From there read the wiki for more information.

Documentation

Documentation for AssetCompress is available on the github wiki pages

Issues

Please report any issues you have with the plugin to the issue tracker on github.

License

Asset Compress is offered under an MIT license.

Authors

See the github contributors list

Changelog

See CHANGELOG for changes only available on master. See github releases for changelogs on previous releases.

asset_compress's People

Contributors

adamroyle avatar admad avatar afolgado avatar challgren avatar codaxis avatar dereuromark avatar dinhani avatar evilbloodydemon avatar fullybaked avatar jadb avatar jeremyharris avatar jiru avatar jmillerdesign avatar joostdekeijzer avatar josegonzalez avatar lorenzo avatar markstory avatar mongorian-chop avatar nojimage avatar peter279k avatar phally avatar renan avatar rynop avatar sime avatar skie avatar stickler-ci avatar thomseddon avatar wyrihaximus avatar yourivdlans avatar zeroasterisk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asset_compress's Issues

AssetCompress->includeAssets(false) does not seem to be working

For debugging my css/js files, I try to use

echo $this->AssetCompress->includeCss(false);

but it looks like its still rendering the build file(s). It looks like the $inline param is not being used in the class at all.

At some point, could you also add params to includeCss($inline=true) and includeJs($inline=true) for those of us that put css in head and JS at bottom? Would allow simple 'false' to be passed to the respective method and everything else would say the same.

thanks

JS files not combining properly

I am including a number of libraries (mootools core, mootools more, and some others after that) into a single build file called 'libs'.

On one file in particular, mootools-1.2.4.4-more.js, it is cut off. I have included all components into the More library, and it gets to line 241, and cuts off part way through, like this:
var Depender = {

    options: {
        /* 
        onRequire: $empty(options),
        onRequirementLo

Then the next line begins the next library file afterward. So, it is not processing the remainder of the mootools more library.

I'm not sure if it's an issue of file size, or the content of the file itself. Anything I include after it works fine, so it's not like it completely stops processing, just that one file.

Unable to process files with mixed case file name

Hi Mark,

I'm trying to include hoverIntent.js bundled with superfish menu package via

$assetCompress->script('hoverIntent')

Since JsFile->_findFile() passes the filename to Inflector::underscore(), the file cannot be found.

  • RC

Passing a base url to the helper

Hi,
i wanted to know if it will be possible to pass a base url to the helper, cause i want my assets to be served by a CDN and i don't know how to proceed with asset_compress.

Very nice plugin by the way.

Pierre

You can have custom filters, but not processors

You know I was talking about making a LESS filter. Well I did and it worked fine, but when I went along and used it in conjunction with normal CSS files (Blueprint CSS framework), the LESS compiler died.

So what I need to do is per-file processing and only if it is a LESS file. What I was thinking is to implement custom processors. They will basically work the same way as the filters only for every file. They will be executed before AssetCompressor::preprocess() in AssetCompressor::process().

The AssetCompressor::$processedOutput property needs a little change too, so the contents of the files remain separated from eachother until all processors have been triggered. After that it will be a simple implode("\n") and then it will continue like it was by calling AssetCompressor::preprocess(), etc.

What do you think? Should I go for it or do you have a better idea?

P.S. I couldn't use underscores because markdown saw it like it should be italic.

Missing Folder class in asset_compressor.php

Just starting to use this plugin - looks very promising, nice work. Js is working fine for me, but when the css_files controller is getting hit, I get:

Fatal error: Class 'Folder' not found in <myapp>/app/plugins/asset_compress/models/asset_compressor.php on line 89 

Do you just need to do a App::import('Core', 'Folder'); before Making a Folder obj on line 89? or is my app not including this core library for some reason, when it should be?

When I add the import line to line 89, and re-run I get:

Failed to load source for: https://<mylocalhostdomain>/cache_css/be2b2b82466d97e351dc2a17c872742d.css?file[]=pages/home&file[]=common/custom&file[]=common/jquery.qtip

Here is the HTML:

<link href="/cache_css/be2b2b82466d97e351dc2a17c872742d.css?file[]=pages/home&amp;file[]=common/custom&amp;file[]=common/jquery.qtip" type="text/css" rel="stylesheet">

Here is my ini. My routes are copy/paste from the wiki.

[Javascript]
searchPaths[] = WEBROOT/js/
searchPaths[] = WEBROOT/js/common/
searchPaths[] = WEBROOT/js/plugins/
stripComments = true
cacheFilePath = WEBROOT/cache_js/
cacheFiles = true
filters[] = JsMin
timestamp = true
stripComments = true

[Css]
searchPaths[] = WEBROOT/css/
searchPaths[] = WEBROOT/css/common/
searchPaths[] = WEBROOT/css/pages/
stripComments = true
cacheFilePath = WEBROOT/cache_css/
cacheFiles = true
filters[] = CssMin
timestamp = true
stripComments = true

I've tried removing CssMin filter, but run into same problem.

1 more piece of info that may help, my web user has write permissions to app/webroot/cache_js and app/webroot/cache_css but I dont see any files written into them.

I'm ubuntu 10.10 64bit, PHP 5.3.3.

any ideas? thx in advance.

can't parse @import

I try use plugins but it can't parse @import. Then i test with this code



but it return result 0. Is REGEX in source code is invalid ?

UTF-8 Byte Order Mark (  )

This character sequence was showing up in one of my asset-compressed CSS files:

/* asset_compress 1304690655 */
body{margin:0;padding:0}

I thought this was a regex parsing issue, so I tried turning off comment removal, manually removing the comments from my source file, and finally tried including a single css file with a single rule and no comments. I tried CssMin. I tried YUI compressor. The characters were still showing up and causing rendering issues on the front-end. I wound up googling for this character sequence, and learned that it is actually the UTF-8 Byte Order Mark, and it can show up when parsers treat file contents as a string. I don't know if there is an easy programmatic fix for this issue, but for anyone else having this issue, I was able to work around it by creating a new file in TextMate and pasting in the contents of my initial file. I'm guessing it was a character-encoding issue, but am not totally sure.

Different Asset Cache destination based on scripts included

I have a bunch of layous JS files, and on a few elements I include an additional JS file...

I could of course, designate one group or another (or both) with a destination but then i'll end up having 2, or 3, or 4 different JS files to download (depending on how many unique destinations I put on a page).

I implemented a somewhat dirty hack which might be a good idea for a feature in the future... basically I have an array of all my scripts to include and create a new destination based on that array... so it's always unique to those scripts, but if those scripts change, the cache file changes...

if (!empty($this->Output->scriptsToInclude)) {
    $destination = 'js-'.md5(serialize($this->Output->scriptsToInclude));
    foreach ( $this->Output->scriptsToInclude as $script ) { 
        echo $this->AssetCompress->script($script, $destination);
     }
}
echo $this->AssetCompress->includeAssets();

Obviously, since AssetCompress helper builds it's own internal array, it would be very easy to implement something like this in the helper, based on a setting.... and I wouldn't have to collect my own array just to pass it into yours.

You may argue that the user would be better off with 2 files to download since they already have one of them in their cache (supposedly) and but those arguments all vary a lot by design and circumstance...

I found this useful and perhaps others will as well.

Problems with joining mutliple JS files due to URL generated by Helper

It seems that commit 81aa014 broke asset generation, at least on my configuration. (I can't find any test cases that test the actual content of the files being built from the urls generated from the Helper, so I couldn't re-create it that way.)

But, if I add some debug to js_files_controller.php in function get(), I can see that $this->params is wrong:

[url] => Array
    (
        [ext] => html
        [file] => Array
            (
                [0] => jquery-1.4.2.min
            )

        [amp;file] => Array
            (
                [0] => jquery.google-analytics

Obviously, it doesn't pick up the second file. If I change the path from using
&
to just
&
it works as it should.

Strip Comments is not to be trusted (JS)

i use quite a few scripts and jquery plug-ins from various sources.

Not all code is equal in its formatting and when strip comments in for JS is turned on it breaks relatively easily.

best way to fix this for now is to disable strip comments.
commit the file to your SCM
turn it back on paste over your generated file and look at the diffs.

I found the following patterns either removed useful code or deleted partial code.

-- Removed entire block

/* COMMENT
MORE
MORE WITH NO *
MORE 
MORE*/
(function($){function Foo(){this.bar=[];etcetc}})

-- Removed partial code

//     {TAB} COMMENT

removed all code until


the next 
valid
close */

$this->params['url']['ext'] = html when set Router::parseExtension('xml','ajax')

I see this error in error.log: "No files found for build file "all.css.html"
and i find out when set Router::parseExtension('xml','ajax') $this->params['url']['ext'] = html .
you try to check in asset_controller.php line 25


A addtional, this isn't bug , i only want ask this:
I switch from previous version to lastest version. I got this error: "Cannot not load filter "CssMin".
My CssMin.php file in APP/vendors/cssmin/CssMin.php . I tried with config:
[filter_cssmin]
path = APP/vendors/cssmin(/CssMin.php)
but it still don't work.
And in documentaion miss config in routes.php,too.

Create LESS, CoffeeScript and UglifyJs filters

LESS and CoffeeScript seem to have good traction, and will work well with the new filter system. UglifyJS creates better compression than JSMin and YUI Compressor, so its worth having as well.

Cached files not being replaced with static files

I did the following:

  • Downloaded the latest copy of Cake 1.3 from Github
  • Installed everything in XAMPP on Windows XP SP3 in the 'htdocs/test' directory.
  • Changed Security.salt and Security.cipherSeed in \app\config\core.php.
  • Downloaded the latest asset_compress from Github and copied it to \app\plugins.
  • Copied the two routes from the Wiki to \app\config\routes.php.
  • Added the directories cache_js and cache_css to the webroot directory.
  • Copied default.ctp from \cake\libs\view\layouts to \app\views\layouts and replaced echo $this->html->css('cake.generic.css'); with $assetCompress->css('cake.generic'); and added echo $assetCompress->includeAssets();
  • Created \app\app_controller.php where I added 'AssetCompress.AssetCompress' to var $helpers

However, when I load http://localhost/test/, this is what is calling my CSS:
href="/test/cache_css/default.css?file[]=cake.generic"

Suggestions?

Does not look for APP/config/asset_compress.ini by default

My asset_compress.ini file in my APP/config directory is never used.

I believe I've traced this to the plugin's asset_compressor.php.

The construct method, unless given an argument containing a valid config path, defaults to App::pluginPath('AssetCompress') . 'config' . DS . 'config.ini';

Enable/disable asset filters depending on debug level

AssetCompress works great, but I've noticed one thing: When debug mode is on and JSMin is enabled, it combines and minifies all JS for subsequent request to the file, since caching is disabled. Currently I'm commenting out the filters while debugging to avoid waiting several seconds for all my JS to minify each time I load a page.

I agree that caching should, by default, be disabled when debug is on, but due to the above issue, I feel additional logic is needed.

The simplest solution would be to disable all filters when debug is enabled, but that would make testing filters harder. In addition, I have one filter in particular that I would want to run no matter what (it updates relative paths to external assets in CSS files so they are not broken when served through the cache URL).

Not sure of the best way to give the user the option of which filters to turn on or off depending on debug level.

Perhaps each filter in the INI file could optionally be followed by something indicating which debug level to disable it at (so maybe "filters[] = JsMin 1" would mean disable JsMin filter if debug level is 1 or greater). Leaving the syntax like it is currently would behave like it does now so as not to affect existing behavior and to make a sane default of 'always enable'.

There might be a better way to do it, though.

More declarative configuration

While the current config works, I think a more declarative configuration would help centralize the behaviour of asset compress, and allow code to be more generic. Keeping a more flexible Helper oriented build system should be kept as well. A better configuration file would allow applying filters to specific build files, and having another set of filters globally. It also opens up the ability to do things like image compression.

A sample config file could be:

[general]
debug = true ; debug on disables output filters.

; define an extension type.
; _filters, _targets and other keys prefixed with this value
; are connected when the ini file is parsed.
;
; cachePath is where built files will be output
; timestamp adds a timestamp to build files.
[js]
timestamp = true
paths[] = WEBROOT/js/*
cachePath = WEBROOT/cache_js
filters[] = sprockets

; each target should have a section defining the files
; everything after js/libs.js is considered the build file.
; all files included in the build are relative to the parent 
; paths key.
; 
; targets can include their own filters.
[js_libs.js]
files[] = jquery.js
files[] = mootools.js
files[] = class.js
filters[] = uglify

; Filters can have their own settings as well
; settings for filters get passed to the filters setting() method.
[filter_uglify]
some = value

; Create the CSS extension
[css]
paths[] = WEBROOT/css/*
cachePath = WEBROOT/cache_css

[css_targets]
targets[] = all.css

[css_all.css]
files[] = layout.css
filters[] = cssmin

The helper would also be able to create build files at runtime using:

AssetCompress->script($build, $files, $attrs);
AssetCompress->css($build, $files, $attrs);

If $files is empty, the helper will just create a url to the build file, which will assume you are using the ini file for all configuration. $attrs would allow you to set additional attributes on the generated tags.

All of these configuration changes should be contained in an object that allows you to either programatically define the configuration, or put it in a ini file.

Compressor dosn't work when theme set in app controller.

When using themes, the asset compress works perfectly when setting the theme in the app controller class definition.

var $view = 'Theme';
var $theme = 'farm';

But when set in the beforeRender or beforeFilter functions (eg, from settings stored in the db) it doesn't work when trying to combine the files.

so

echo $this->AssetCompress->includeAssets(false); 

works fine f- each css file is included seperatly, but

echo $this->AssetCompress->includeAssets(false);

dosn't work - the css file has no css, just the text 'array'

Not reading CONFIGS.'asset_compress.ini'

It's using the default config.ini even though I have a valid app/config/asset_compress.ini

I thought upgrading fixed it, and I see the following in the constructor:
if (empty($iniFile)) {
$iniFile = CONFIGS . 'asset_compress.ini';
}
but it's not loading my config file unless I replace the default config.ini

Include some base filters in the plugin

It's great that users can create their own asset filters and use combine them as required, but I think it would be cool if the plugin had some 'default' asset filters for common use cases built in.

I've created some basic ones for the most common JS and CSS tools and included them on the 'filters' page in the wiki... hope that's OK :)

I'm wondering it it wouldn't make sense to include some or all of them in the base plugin--allow users to override them by putting replacement files in their app/lib directory, but this would mean that for most use cases people don't need to create or modify filters.

specify media type for css files

Is there a way to specify the media type for the compressed files output by AssetCompress?

I'd like to send most of my CSS files to a particular compressed file (which already works fine), but specify that file as the 'screen' media type. Then I'd like to send a couple other CSS files to a second compressed file (which also works) but specify that one as a "print" media type.

So, basically, is there a way to specify custom attributes for the tags that AssetCompress outputs, and if not, would you consider building that in? I haven't had time to dig into this one very much, so correct me if this is something that is already present that I'm just not seeing.

Thanks!

Assets inside plugin folder

Hi, I don't know if this feature is already implemented and I'm missing to use it, but I would like to include and to compress some css files which are stored inside the webroot/css folder of a plugin. Is this possible? I'm failing to add them.

Thanks!

Support glob-ish syntax for searchPaths

Configuring an application with many searchPaths is a pain right now. It would be ideal if you could specify searchPaths like:

searchPaths[] = WEBROOT/js/*

This would recursively scan the subtree at app/webroot/js. In addition to this, filesystem scanning should probably be refactored into a separate class so filters can access that functionality as needed.

Minified jQuery UI with CR line ending not included

This is a strange one as well. Try to include /jquery-ui-1.8/ui/minified/jquery.ui.autocomplete.min.js from an old version of jQuery UI: http://jquery-ui.googlecode.com/files/jquery-ui-1.8.zip

It doesn't work, because of the odd line feeds in the file (all CR/LF and then a CR at the end). If I set it to all LF, it works. If I set it to all CR, it doesn't work (nothing is included at all, probably stripped by the comment remover?).

Newer versions of jQuery UI doesn't seem to have the same "problem", but there might be other bundles out there with CR linefeeds.

Javascript view files not being included

_includeViewJs had some oddities, it was not working at all.

I fixed it by changing the foreach block to this:

    foreach ($files as $file) {
        $includeFile = JS.$this->options['autoIncludePath'] .DS. $file;
        if (file_exists($includeFile)) {
            $this->Html->script($this->options['autoIncludePath'].'/'.$file, array('inline' => false));
        }
    }

Big changes are appending the JS constant when locating the file on the filesystem, as well as properly adding a directory separator where needed.

This is fixed in my fork, if you'd care to merge it.
http://github.com/bmcclure/asset_compress

Typo in AssetCompressor model

~ line 219

foreach ($this->setttings['filters'] as $filter) {

should be

foreach ($this->settings['filters'] as $filter) {

CSS filters actually start working then :)

Scripts included in layout is preceeded by script included in view file.

This causes a problem when you include jquery in the layout file and then in the view file, you include a plugin that requires jquery. The plugin.js precedes jquery.js in the html source code so your js doesn't work.

I managed to solve the issue by changing script function in the helper file thus:

public function script($file, $destination = 'default') {
    if (empty($this->_scripts[$destination])) {
        $this->_scripts[$destination] = array();
    }
    $this->_scripts[$destination] = array_merge($this->_scripts[$destination], (array)$file);
    $tmp[$destination] = $this->_scripts[$destination];
    unset($this->_scripts[$destination]);
    $this->_scripts = array_merge($tmp, $this->_scripts);
}

Might not be too clever, but worked for me.
Perhaps there is some way we could send a flag saying wich order you would like to use?

Themes and cake asset_compress build

Hi,

I've been using the asset_compress plugin for quite a while now, really love it!
Recently i've updated the asset_compress from 0.2 to 0.3, so i can now use the "build" shell command (also simplifies my automatic deployments).
However, i'm using themes for a cakephp project (also with asset_compress), and whenever i needed to update the build files, i would use "clear" to remove them and refresh the pages with different build files to recreate them.

Now i thought i could use the "build" command to automatically create all build files (4 to be exact). unfortunately this doesn't work because the shell task will not look in the theme folder, and when i would add these folders to the searchPath (e.g. APP/views/themed/my_theme/webroot/css/) and the same file names would be used across themes only the first one found would be included (say style.css).

Is there a way of modifying the build task to create build files for themes?

two different JS files with the same name AssetCompressor willntake the first one found

In the case where there are two different JS files with the same name AssetCompressor will take the first one found...

I think it would be better to specify the path while including the JS file, using cakeph's standard notation to locate the file, instead of a SearchPath[] array in asset_compressor.ini.
It would be nice to be able to change $this->Html->script(...) -------> $this->AssetCompressor->script(...) leaving paths in the same way.

Collapse Filters and Processors

Having two similar but different ways of extending AssetCompress seems a bit silly. It might be worthwhile collapsing filters and processors, and provide a unified API for both.

  interface AssetFilterInterface {
    public function settings($settings);
    public function input($content, $inputFilename);
    public function output($content, $outputFilename);  
  }

The input function would be called once for each file being processed, and be given the settings for the file type being processed. The return of all input methods would be concatenated together. Once this was complete, the output method would be called once for each filter. This would give one way of extending the plugin, and allow the @import() and //= require syntax to be extracted as well. Having access to the searchPaths means a filter object could traverse the filesystem as well.

Relative background image path in themed css files

What is the proper way to configure asset compress so that it supports css file containing

background: url('../img/logo.png');

Currently, this does not work since cached files gets written below WEBROOT/cached_css and the image file is in WEBROOT/theme/mytheme/img.

Perhaps it's better to cache css files into WEBROOT/theme/mytheme/cached_css instead?

Not use Jsfilter (CssFilter) in debug mode

Now , even in debug model asset_compress always use filter to minify css and javascript. It shouldn't use filter in debug mode.

    public function filter($content) {
                if ( inDebugMode ) return $content;
        return JsMin::minify($content);
    }

With a large javascript file JsMin::minify can take several seconds minify it .

AssetProcess::environment() returns empty array for YuiCss

I'm trying to use YuiCss filter to compress my css. Running into the following problem:

Call to a member function command() on a non-object in /app/plugins/asset_compress/libs/asset_filter_interface.php on line 93

After debugging a bit, it looks like $Process->environment($environment) is returning and empty array - because YuiCss::output() is not passing an $env.

I can't figure out what the environment is used for, otherwise I would submit a patch. When debug = true in the ini, everything works (cuz its not going thru the filter). My ini is below. I'm on ubuntu 10.10 64bit.

[General]
writeCache = true

[js]
timestamp = true
cachePath = WEBROOT/cache_js/
filters[] = YuiJs

paths[] = WEBROOT/js
paths[] = WEBROOT/js/*

;############## JS build files     ####################
[js_common.js]
files[] = common/plugins.js
files[] = common/commonscript.js
files[] = plugins/jquery.qtip.pack.js
files[] = common/helptips.js

;############## End JS build files ####################


[css]
timestamp = true
cachePath = WEBROOT/cache_css/
filters[] = YuiCss

paths[] = WEBROOT/css
paths[] = WEBROOT/css/*

;############## CSS build files     ####################
[css_common.css]
files[] = common/custom.css
files[] = common/jquery.qtip.css

;############## End CSS build files ####################

no JS is sent if cache is deleted and debug>0

The JS requests reads: Fatal error: Class 'DebugKitDebugger' not found.

This happends if I delete the cached JS and set debug>0.

I have cacheFiles = true.

I think the expected thing to happen is that if

cacheFiles = false: compressed JS gets regenerated
debug>0: compressed JS gets regenerated
cache file deleted doesn't exist: the plugin regenerates a new one

I'm maybe misleaded by something here...

cacheFiles = false, but it still sends the same cached file

Although I put in asset_compress.ini

cacheFiles = false

The changes I made to my JS file are not sent to the browser, instead it is sent the cached version. Same happened when putting debug>0... I had to debug=0 and delete the cache so the new one would be generated...

Active theme not being picked up anymore

Could it be that the plugin is not picking up on active themes anymore (I am using the latest commit)?

I have set up an active (and working) theme in my app_controller but the check in css_files_controller.php's beforeFilter just doesn't detect it so it never looks in the theme directory where the css resides.

Assets included from views do not work with cacheFiles = true

First off this plugin has lots of potential - I really like it. I was drawn to it over mcurry's asset implementation because I can split up where css and js are echoed out in the resulting HTML (so i can move JS to the bottom of the page to improve perf).

However, I'm running into an issue when cacheFiles it turned on, when including an asset from a view. Everything works as expected when cacheFiles = false. Here is what I'm seeing (using css only to keep things simple):

My config.ini:
[Css]
searchPaths[] = WEBROOT/css/
stripComments = true
cacheFilePath = WEBROOT/cache_css/
cacheFiles = true
filters[] = CssTidy

My layout/default.ctp:
...
$assetCompress->css(array('style','common','icons'));
echo $assetCompress->includeCss();

$assetCompress->script(array('common','jquery/common','jquery/jquery.bgiframe.min'));
echo $assetCompress->includeJs();
echo $scripts_for_layout;
...

I then have a view (call it views/foo/index.ctp) that does the following:
$assetCompress->css(array('register'));

  1. If I first request a view that does not include any css asset (like my homepage for example) I see the following:

  2. This creates a WEBROOT/cache_css/default.css file.

  3. I then request /foo (the /views/foo/index.ctp). The default.css is picked up - but its missing the contents of register.css...

Alternative flow:

  1. Now if i clear the cache_css/default.css file, and access the foo view first I get:

  2. This again creates a WEBROOT/cache_css/default.css file. HOWEVER, this time the contents of register.css is in default.css

If I set cacheFiles = false, then everything is fine, as the query string is dynamically including the right css files based on what my view and its layout are specifying as assets to compress.

What am I doing wrong here? Does your plugin only support "including" css files in the layout? Shouldn't the resulting cached file be named after all the css files that make it up? so for example mine would be style_common_icons_register.css or something? That way I can call $assetCompress->css() from within my view, and let assetCompress handle combining css from my layout,view, and maybe even any elements that are part of a view...

AssetHelper::__construct() takes argument $options but doesn't use it

The __construct() method of AssetHelper takes an argument, $options, but it doesn't use it anywhere in the constructor.

This causes a warning in your included test for the helper as well:

Warning (2): Missing argument 1 for AssetCompressHelper::__construct(), called in /home/deutilit/scripts/webmanager/plugins/asset_compress/tests/cases/helpers/asset_compress.test.php on line 13 and defined [APP/plugins/asset_compress/views/helpers/asset_compress.php, line 86]

Does that need to be there? Will it be used in future versions?

Combined file not being written to cache dir

I apologize in advance because this is one of those difficult issues, and may very well be human error on my part, but I've pulled out a fair amount of hair so I'm going to give it a shot and see if anyone has some insight.

I have asset_compress working great in development (OSX/Apache2/PHP5.3). Once I move it to production (Ubuntu/Nginx to Apache/PHP5.3) it ceases to write the combined JS file to webroot/cache_js. Both are running the latest version of Cake 1.3.

I have asset_compress.ini setup just like in development.
I have the routes setup exactly the same as in development.
The folders(cache_js & cache_css) are setup in webroot and set to 777.
The helper is writing the time to tmp/asset_compress_build_time.
When the helper writes the script tags it's writing:

<script type="text/javascript" src="/cache_js/common.1291384289.js?file[]=modernizr-1.6.min&amp;file[]=jquery.orbit.min.js&amp;file[]=underscore-min&amp;file[]=mustache.min&amp;file[]=plugins"></script>

Debug is set to 0 in production.

It just won't seem to write the combined file into the cache directory. I've monkeyed around with the settings in all different ways, and just can't seem to get a solution.

This is my INI file:

[Javascript]

searchPaths[] = WEBROOT/js/
stripComments = true
cacheFiles = true
timestamp = true
cacheFilePath = WEBROOT/cache_js/

[Css]

searchPaths[] = WEBROOT/css/
searchPaths[] = WEBROOT/css/skins/
stripComments = true
timestamp = true
cacheFilePath = WEBROOT/cache_css/
cacheFiles = true

Thanks for your help.

D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.