Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not reload cache when @import less files are changed in development #274

Open
issackelly opened this issue May 31, 2012 · 19 comments
Open
Labels

Comments

@issackelly
Copy link

It's pretty straightforward

template.html

{% compress css %}
    <link rel="stylesheet" href="{{ STATIC_URL }}less/bootstrap.less" type="text/less" />
{% endcompress %}

bootstrap.less

...
// Custom classes for Nebula. Stylesheet.less will keep getting smaller until we have as little customization as possible.
@import "_stylesheet.less";

If I make a change in _stylesheet.less, I have to restart runserver to see the change. compress doesn't do it automatically.

I know that there are several ways around this, it's just a bug I encountered.

Here are my settings

>>> from django.conf import settings
>>> settings
<django.conf.LazySettings object at 0x10842e1d0>
>>> settings.COMPRESS
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/issackelly/.virtualenvs/nebula/lib/python2.7/site-packages/django/utils/functional.py", line 277, in __getattr__
    return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'COMPRESS'
>>> settings.COMPRES
KeyboardInterrupt
>>> settings.COMPRESS_OFFLINE
False
>>> settings.COMPRESS_ENABLED
True
>>> settings.COMPRESS_URL
'/static/'
>>> settings.COMPRESS_PARSER
'compressor.parser.LxmlParser'
>>> settings.COMPRESS_PRECOMPILERS
(('text/less', 'lessc {infile} {outfile}'),)
>>> 
@cfletcher1856
Copy link

I am having a similar issue

{% compress css %}
<link type="text/less" rel="stylesheet" href="{% static "less/style.less" %}">
{% endcompress %}

stlye.less

@import "../bootstrap/less/bootstrap.less";

It is pulling in a bootstrap.less but not the one it should be. When I make changes to the bootstrap file no changes are made, but if i change the name of the file and the import, ex. bootstrap2.less it works just fine.

Does compressor cache the import files?

I would really like to get this fixed.

Thanks for any help

@webjunkie
Copy link

The only way to solve this issue seems to use compress offline. Or did anyone find another solution?

@mynameistechno
Copy link

+1

@mynameistechno
Copy link

Did anybody ever resolve this?

I don't really see how compressor would be able to solve this since this is implemented as a filter, i.e. it is out of it's control. If you touch the parent file and run collectstatic it seems to work.

What I'm doing now is this:

http://www.caktusgroup.com/blog/2012/03/05/using-less-django/

@webjunkie
Copy link

Well compressor could parse the less file and check the all the referenced files for the modification times...

@diox
Copy link
Member

diox commented Feb 14, 2013

That would mean compressor should know how to parse and detect included files for every pre-compiled format on earth, not just less...

@webjunkie
Copy link

Uh, yes... that would be a bit of a stretch... any other ideas?

@diox
Copy link
Member

diox commented Feb 15, 2013

One solution is to simply use COMPRESS_ENABLED = False for development, which doesn't de-activate the precompilation step. Ironically, some users complained that compressor doesn't cache the results when COMPRESS_ENABLED is False... (see #346) It's hard to please everyone :)

@mynameistechno
Copy link

To have a filter-independent solution, a possibility is to have optional configuration that instructs compressor of file dependencies (in this case, less file imports).

E.g. app.less is included on page and imports other less files:

app.less -> footer.less, typography.less

So that when app.less is encountered by compressor it checks to see if footer.less and typography.less have changed in addition to itself. If so, it pre compiles app.less.

Thoughts?

Sent from my iPhone

On Feb 15, 2013, at 2:52 AM, Julian Bez notifications@github.com wrote:

Uh, yes... that would be a bit of a stretch... any other ideas?


Reply to this email directly or view it on GitHub.

@diox
Copy link
Member

diox commented Feb 15, 2013

IMHO, this goes against one of django_compressor's core principles : you shouldn't need to play with settings to generate the compressed content. Also, this violates DRY since you have your dependencies specified twice (once in the file itself, once in the settings). This is bad for maintenance.

@mynameistechno
Copy link

I guess I'll have to try compression = false again ... But I don't think that worked for me last time I tried it.

I know it's not optimal or DRY, but it's really the developer's problem at that point. To me it's better than other available options.

Sent from my iPhone

On Feb 15, 2013, at 10:18 AM, Mathieu Pillard notifications@github.com wrote:

IMHO, this goes against one of django_compressor's core principles : you shouldn't need to play with settings to generate the compressed content. Also, this violates DRY since you have your dependencies specified twice (once in the file itself, once in the settings). This is bad for maintenance.


Reply to this email directly or view it on GitHub.

@Wilfred
Copy link

Wilfred commented May 24, 2013

For what it's worth, it's pretty straightforward to parse Less for imports. Just strip out comments with a regexp, then look for @import text. I implemented it for (the now abandoned) django-mediagenerator: https://github.com/potatolondon/django-mediagenerator/commit/5d48010dc25b4d482c751f880d6e1e3fc2351955#L0R174

Would you be wiling to accept a PR that did this for django_compressor?

@honi
Copy link

honi commented Mar 6, 2014

It isn't a big deal to have COMPRESS_ENABLED = False in development, but then the generated CSS is not passed through the configured filters, in particular CssAbsoluteFilter, which is very useful.

Maybe if there could be some way to tell compressor to use specific filters even if compression is disabled?

@mynameistechno
Copy link

I've been giving django-pipeline a shot and it handles this pretty well at first glance.

Sent from my iPhone

On Mar 6, 2014, at 5:37 AM, Joni Bekenstein notifications@github.com wrote:

It isn't a big deal to have COMPRESS_ENABLED = False in development, but then the generated CSS is not passed through the configured filters, in particular CssAbsoluteFilter, which is very useful.

Maybe if there could be some way to tell compressor to use specific filters even if compression is disabled?


Reply to this email directly or view it on GitHub.

@honi
Copy link

honi commented Jun 22, 2014

I'm using this management command to detect changes in all .less files in my project and then touch the main less file which is included in the html so that django-compressor recompiles.

@mynameistechno
Copy link

Thx for heads up, however I've since moved on to django-pipeline which deals with this nicely.

On Jun 22, 2014, at 12:28 PM, Joni Bekenstein notifications@github.com wrote:

I'm using this management command to detect changes in all .less files in my project and then touch the main less file which is included in the html so that django-compressor recompiles.


Reply to this email directly or view it on GitHub.

@ezy
Copy link

ezy commented Jul 27, 2014

COMPRESS_REBUILD_TIMEOUT = 0 worked for me in local_settings

@velle
Copy link

velle commented Dec 29, 2014

I'm having the same problem. I thought "manage.py compress --force" should deal with this, but it does not. It generates a new css file in static/CACHE, but the link elements in the html files don't change and still point to the old version in static/CACHE.

AFAICT "manage.py compress --force" is only useful if one accidentally deleted the files in CACHE.

Is that really the intended behavior?

@diox diox added the feature label Sep 26, 2015
@k-funk
Copy link

k-funk commented May 21, 2016

I think that this PR's solution is best because:

  1. We still only define file dependencies in one place (this concern).
  2. All files listed within blocks that have the group_first=true flag will get watched, and the group will recompile on change, so that server restart isn't required (OP's concern).
  3. It's optional — won't break anything going forward.
  4. Filter's don't need to require any changes to make them work.

The only downside is that other @import's within defined dependencies won't be caught when modified. However, I like this problem better than the current one:

  • I can't use variables.scss, mixins.scss, ....scss that all other files depend on
  • A server that doesn't notice/pickup file changes because they were @imported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants