kriswallsmith / assetic

Asset Management for PHP
MIT License
3.76k stars 559 forks source link

Assetic is not aware of asset dependencies #79

Closed matteosister closed 11 years ago

matteosister commented 13 years ago

As discussed here there is a problem with the new implementation of the compass binary. The problem is that, the cache system, checks the timestamp of the sass file without involving the filter. So if you have a main file which imports other "subfiles" (a typical situation working with compass) and you never edit this main file you never get a recompile.

The process of check the timestamp of an assetic file should in some way involve the filter to get a complete list of files to check and eventually trigger the recompile by checking all the timestamps.

This issue is related to compass, but I think it should also appear in Sass and ScssFilter and also on any filter that deal with an asset with a tree of subassets

kriswallsmith commented 13 years ago

I've begun work on this in the mtime-aware branch.

matteosister commented 13 years ago

is it already testable?

kriswallsmith commented 13 years ago

not yet.

On Jun 24, 2011, at 9:01 AM, matteosister reply@reply.github.com wrote:

is it already testable?

Reply to this email directly or view it on GitHub: https://github.com/kriswallsmith/assetic/issues/79#issuecomment-1433307

srosato commented 13 years ago

What's the state of this issue? Seems like it was postponed, were there any difficulties?

kriswallsmith commented 13 years ago

This is not going to make it into 1.0 unfortunately, but it will probably be the only enhancement in 1.1.

kriswallsmith commented 13 years ago

Some open questions:

And probably more...

kriswallsmith commented 13 years ago

See #96 also.

matteosister commented 13 years ago

do you think it's possible to use some native ruby implementation (link this) or plain php to parse line by line the sass/scss files?

pkruithof commented 12 years ago

What's the status on this issue? Is it possible to disable caching completely (on development environments of course) until this is resolved?

matteosister commented 12 years ago

disable caching could be a good solution....but I don't think there is a "clean" way to do it... at the moment I use compass normally as a gem for big projects. For small projects with just few hundreds of line of css code you could use a single file....or remember to change something in the main file if you want assetic to recompile...

pkruithof commented 12 years ago

This is not always the case: when doing minor CSS tweaking you constantly have to save two files, where you want to be fast switching between editor and browser. I know that tweaking in an inspector is faster and sometimes better, but even then I still switch between editor and browser regularly.

As for small projects: I'm currently working on a project where I keep the media query specific CSS in separate files, and import them at compile time in media queries, but also without media queries for IE<9. There are other use cases to think of where using imports is much more handy, even though the size is not that large.

Edit: this is a separate discussion for a disable-cache flag, obviously. Let's focus on the main issue here. :)

srosato commented 12 years ago

The workaround I've been using for the past weeks is "double watching" my files. I fire up the compass watch with a config.rb file to watch for scss file changes, and use assetic to watch on compass' compiled css files. This double watching for now is a bit annoying, but works well until assetic can support dependency watch.

matteosister commented 12 years ago

@pkruithof I'm using a single file just because of assetic...normally I use only external files, and in my main file I only import things

@srosato So you are not using the CompassFilter..but some css filters (like yui compressor)? It's a shame because compass itself compress css files pretty well....

To me a solution could be: define a list of dependencies given a base file, and assetic should watch all the timestamps. This could be a quick workaround to the big problem of checking sass files dependencies in php (in ruby it's easy like calling a function)

srosato commented 12 years ago

Yeah I know it's a shame for now, yeah I'm using other filters like CssRewrite and YuiCompressor after compass compiled the css files, but not the CompassFilter for now since the asset dependency watching is a must for me. I wish I had a little more time as I would try to give a hand on this issue by contributing.

matteosister commented 12 years ago

I hope that this pr will bring some quick solution for all these problems...

jrmyio commented 12 years ago

Also waiting for a solution...

matteosister commented 12 years ago

@ConneXNL, @srosato here is a solution... CompassElephantBundle

redemption commented 12 years ago

+1 on needing a solution for Less

matteosister commented 12 years ago

@redemption quick solution waiting for this issue to be closed

https://github.com/matteosister/LessElephantBundle

if you try it please let me know if it works for you.

schmittjoh commented 12 years ago

also related to #190

matteosister commented 12 years ago

@schmittjoh are there any plans to find a solution for all these problems? I'm really curious to see what direction assetic will take (assets scan, native binary) and how to implement a filter that can trigger the asset staleness check. I was hoping that inotify could give a solution....but It's not been merged in sf yet.

mrclay commented 12 years ago

My plan for Minify is to have smart assets ("sources" in Minify) that know how to linearize and manage watching the dependency files for changes. Internally they would cache the list of dependencies so getLastModified() could simply get the max() of all the dependencies. getContent would re-linearize everything and cache the new list.

This, of course, bypasses all the questions about how dependency files are treated: they're treated as a single asset, period. I'm not all that familiar with LESS yet, but maybe a similar LessLinearizerAsset could do the same thing for LESS: just process the imports and leave the processing for the filter. If LESS requires distinct files for vars I guess this wouldn't work.

digitalkaoz commented 12 years ago

any updates on this one? its a real showstopper.

arcanis commented 12 years ago

Isn't there a way to disable the cache in dev environments ?

matteosister commented 12 years ago

@arcanis I don't think it's a solution, but only a workaround...

arcanis commented 12 years ago

Didn't say it was a solution. But until we found a solution, it would be great to at least have a workaround.

And actually I think it could be a solution. In a dev environment, why using a cache ?

matteosister commented 12 years ago

@arcanis because something has to be cached I think. Or you end up waiting for 25 secs for every request. Anyway, don't know if there is a way, and never tried it. If you find a way and it works without performance issues let me know.

pehbehbeh commented 12 years ago

any updates? would be nice to find a solution

fran6co commented 12 years ago

I made #259 to fix this issue, but still pending approval. =/

k0pernikus commented 11 years ago

I really would love to see this fixed.

matteosister commented 11 years ago

@k0pernikus do you use compass? or sass only?

k0pernikus commented 11 years ago

@matteosister I use both compass and sass.

matteosister commented 11 years ago

check https://github.com/matteosister/CompassElephantBundle it uses directly the compass binary so everything works as expected...

CraigMason commented 11 years ago

FYI, a little workaround would be to use something like the following:

watch -n 1 touch basefile.sass
bakie commented 11 years ago

What is the status on this ? Trying to use it for sass files but not going to use it if the imports don't get compiled when changed.

xzyfer commented 11 years ago

We've solved this issue where I work by using a non-persistent asset cache. Unfortunately this means we're essentially rolling with no cache. It's slightly better than rolling with no cache at all since we're able to have a consistent interface.

@see #317 for my implementation of this for you own work.

For those using the AsseticBundle in Symfony2, you can use enable this non-persistent cache by setting assetic.filter.cache: <namespace/class> in your parameters_dev.yml

bakie commented 11 years ago

Did you mean assetic.cache.class: Assetic\Cache\ArrayCache This works for me. Thanks!

xzyfer commented 11 years ago

Yes I did, my apologies I was trying to recall from the top of my head.

On Saturday, October 27, 2012, stephaneb notifications@github.com wrote:

Did you mean assetic.cache.class: Assetic\Cache\ArrayCache This works for me. Thanks!

— Reply to this email directly or view it on GitHub.

< https://github.com/notifications/beacon/kUiJMsAlwi46O3Xx02uS8k0QxxDamnhCu9cZiy8U1XIUblGU1va5OxGJtE3TdZvG.gif

Regards, Michael Mifsud

T: twitter.com/xzyfer | G: gplus.to/xzyfer

jrmyio commented 11 years ago

This doesn't solve the assetic:dump --watch during development, does it?

arcanis commented 11 years ago

Hm I get an error "Unrecognized options "cache.class" under "assetic"" with dev-master, is it the correct property ?

[edit] Nevermind, it has to be in property.yml, not in config.yml

stof commented 11 years ago

@arcanis You have to change the assetic.cache.class DIC parameter, not a setting in the semantic configuration of the bundle

arcanis commented 11 years ago

@stof Yep, I figured it out few seconds before your post. Thanks !

igorpan commented 11 years ago

I tried using assetic.cache.class solution but no avail. I still need to alter my main file (add whitespace or something) and only then will it recompile it with imported file changed.

Then I checked if "assetic.cache.class: Assetic\Cache\ArrayCache" has effect at all, so I changed it to invalid value "assetic.cache.class: Assetic\Cache\SomethingRandom" and I got an error in CSS files which means it has effect but it doesn't work for some reason.

Strangely enough, when I returned parameter to "ArrayCache" class, it updated my CSS files with new values. Any ideas on this?

mpdude commented 11 years ago

How does the ResourceWatcher component (Symfony PR 4605 blocked by Symfony PR 4619) relate to this?

Based on that, we could configure dirs, files and patterns to watch (per filter or asset?) and expire the asset cache whenever there are changes.

There can always be resources used but "hidden" behind filters and Assetic can't figure those out. A manually configured "watchlist" is not as bad as having to touch "main" asset files every time a "hidden" file changes.

stof commented 11 years ago

@mpdude it has nothing to do with this. The issue here is to determine what the resource are.

The ResourceWatcher component is about running an action as soon as one of the resources changes. It won't help if you are missing some resources in your list. Thus, Assetic itself is not doing any resource watching (which supposes a long running process doing the dump regularly). The only part which could relate to the ResourceWatcher component is the implementation of the --watch option in AsseticBundle's dump command (which is currently doing the watching itself with some Assetic specific code).

mpdude commented 11 years ago

I was thinking about manually configuring a set of directories, files or globs as the what, since Assetic cannot figure that out itself. ResourceWatcher looked like a good approach to check this set for changes, additions and removals of files.

But if I got you right, ResourceWatcher will be useless on a per-request level (the AsseticController feature)?

stof commented 11 years ago

@mpdude the goal in this issue is precisely making Assetic able to figure what (because finding other files included when applying the less filter for instance is possible with the source). There is some experiments about the way to integrate this in Assetic already (latest one is #362).

The ResourceWatcher is not about finding resources but about knowing if the known resources have changed and to trigger an action as soon as it happens. Assetic does not need it as it is already able to figure if its resources have changed.

ghost commented 11 years ago

@kriswallsmith : assetic is aware of such dependencies now right? or is this something else?

kriswallsmith commented 11 years ago

Please open additional tickets for any asset-dependency related issues or requests.

arcanis commented 11 years ago

@kriswallsmith Not sure to understand, is this issue closed as 'wontfix' or 'solved' ?