Skip to content

Conversation

@zoubin
Copy link
Contributor

@zoubin zoubin commented Aug 18, 2015

I'm using postcss to split css into modules, and postcss-import plays a great role. As there are increasingly many css files to generate, some common modules imported may have to be read many times, which makes the performance worse and worse.

Suppose there are two files to compile:

a.css

@import "mixins.css";
.a{}

b.css

@import "mixins.css";
.b{}

It seems that mixins.css will be read twice.

I think options.cache is able to fix that problem, by caching the transformed file contents and sharing it globally.

Moreover, if the cache is manipulatable externally, some file watching tools (like watchify ) can also work with postcss easily.

I see #47 handles in some way. But that pr has failing checks.

What are your opinions?

@MoOx
Copy link
Contributor

MoOx commented Aug 25, 2015

I guess it's a nice start & a good small step to an even more smart cache (parsed ast in a huge file like #47). Tests looks good.
I think we should merge this one so we can iterate more easily. What do you think @
andyjansson ?

@zoubin
Copy link
Contributor Author

zoubin commented Sep 2, 2015

I guess it's a nice start & a good small step to an even more smart cache (parsed ast in a huge file like #47). Tests looks good.
I think we should merge this one so we can iterate more easily. What do you think @
andyjansson ?

@andyjansson

@andyjansson
Copy link

@MoOx @zoubin So, judging by the code, this is to inject CSS via JavaScript..? That doesn't seem like a cache to me.

Also, speaking of #47, everything is implemented. It caches imports and automatically invalidates the cache for the files (and any dependents of the files) that have been modified. The only reason it has failing checks is because it's out of sync with the upstream repo - the tests pass! I just need help bringing it up to speed with the upstream repository. @jedmao did a PR which refactored the code base which might things a bit more difficult to merge, but I think the code is overall better for it.

So, if anyone is able to help, I'd be grateful.

@zoubin
Copy link
Contributor Author

zoubin commented Sep 2, 2015

@andyjansson

So, judging by the code, this is to inject CSS via JavaScript..? That doesn't seem like a cache to me.

Perhaps the test code is a little misleading.
I do not mean to inject CSS via JavaScript. The contents of options.cache are only set by postcss-import. When postcss is run multiple times, this cache will persist, so that each file will be read at most one time.

Another reason for options.cache is that we can watch imported files given by onImport, and if any watched file changes, we can invalidate the corresponding cache in options.cache, and restart the compilation to renew the result.

@andyjansson
Copy link

@zoubin This is already handled in #47. It caches the file, reads it once and invalidates the cache automatically if the file has been modified.

@andyjansson
Copy link

In #47, this is what happens to the cache if a modification to a file in the dependency graph is detected:

Detection is done when postcss-import is invoked by looking at the mtime file info. No watchers needed.

@TrySound TrySound closed this Jan 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants