-
Notifications
You must be signed in to change notification settings - Fork 55
Add methods to allow generation of critical CSS for a specific route … #11
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
Add methods to allow generation of critical CSS for a specific route … #11
Conversation
On my first walk-through, this is awesome!!! I'll run this by my team asap, and then we'll merge this in. |
After having some time to review, I really am excited about the addition and it should provide great value to the project. Here are a few suggestions: While convenient, I think we should remove arguments that allow for silent method failure, i.e. def self.generate(route)
Rails.cache.write(route, CssFetcher.new.fetch_route(route), namespace: CACHE_NAMESPACE)
end
def self.clear(route)
Rails.cache.delete(route, namespace: CACHE_NAMESPACE)
end
def self.clear_matched(routes)
Rails.cache.delete_matched(routes,namespace: CACHE_NAMESPACE)
end
def self.clear_all
clear_matched('*')
end We'll probably need to update anything currently referencing It may be helpful to include Let me know what you think! |
Good suggestions. How important is it to be backward compatible? Removing the default def generate_for (route)
Rails.cache.write(route, CssFetcher.new.fetch_route(route), namespace: CACHE_NAMESPACE)
end We would leave the existing I like the changes to the Thoughts? |
Hmmmm, It's tough to gauge how many folks are actually using this, but given the issues reported and contributions made, I think we should maintain backwards compatibility until a larger change is requested/introduced. With that being said, I like the idea using On a side note, I plan to attempt to move away from Penthouse to Critical CSS. This change should produce a major/minor version bump. I'm thinking in the short-term a method_alias could be added for Regarding the Once these changes have been completed, we should be good to go to get this PR merged in. Thanks again for the contribution and let me know if you have any other thoughts/feedback. |
Now that I think about this some more, I really like the idea of using |
I just force pushed an update that uses |
Sorry for the delayed response. I meant to respond yesterday... After some thought, let's go ahead with the With that being said, the version should be incremented to 0.3.0 because of the above. Side note, I don't have a preference with |
Okay. I like |
…and to allow removal of specific routes from the CSS cache.
Sorry this took so long. I just pushed an update to make the changes we suggested. It looks like there are some merge conflicts. Would you like to pull them down and resolve them or would you like to take care of it? |
I rebased and now we can merge without issue. |
This should be ready to merge. Do you see any issues? |
@taranda Sorry for the delay. The work looks solid, but I want to test this locally first due to the absence of a test suite. I'd like to get this merged in by EOW, however. |
No worries. Thanks. |
I found two quick things: First, we need to add Second, def self.clear_all
self.clear_matched(/.*/)
end We may want to make that clear in the documentation as well if Likewise, I stumbled upon that Once these two changes are in, I think this is ready to be merged in. |
Hmm. I changes the What caching systems would you like to support? Since Memcached is not supported already, I recommend supporting Redis. We could remove the |
Could we do something like I'm fine with removing the method unless there's a huge need for it. I'd like to support as many options as possible. |
I think Rails.cache.clear will clear the entire cache. At least it did with my experiments with a Redis cache. In other words, you cannot clear one namespace. It may be implementation dependent. We could remove the I know Redis likes |
Yeah, I'm fine with your solution of remove the |
Those changes have been pushed up. You may want to retest. |
How are things looking? |
Sorry for the delay. I think i'll have time to test this later today |
No worries. |
…and to allow removal of specific routes from the CSS cache.
This modification exposes some methods allowing the developer to generate specific routes dynamically. It also allows the developer to clear routes from the cache. With these added tools, developers can dynamically generate critical CSS without relying on hardcoded routes in
critical_path_css.yml
.This could solve this first issue in the backlog. For example, a user could add all of the URLs for a
products
resource with the following code snipet:It does not allow the user to add controller routes to the config yml, but it gives the developer the tools he/she needs to add all of the routes for a resource to the cache.
It also allows developers to dynamically generate critical CSS for their whole app without having to remember to hard code all of routes in the configuration yml. Here is a sample implementation of dynamically generated critical CSS
This pull request is completely backward compatible with previous versions.
I look forward to your feedback.