-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fixes #2
base: master
Are you sure you want to change the base?
Fixes #2
Conversation
@@ -6,9 +6,8 @@ class Rewrite | |||
|
|||
delegate :request, :params, to: :template | |||
|
|||
def initialize(template, manifest: template.asset_url('application.css'), version: Config.version, skip: false, cache: true, &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way this is written you should be able to override the name of the manifest manually when you call this method. I call it like this:
= RailsCriticalCssServer::Rewrite.call(self,
skip: current_user.present?,
manifest: asset_url('css_manifest.css')) do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true. but then you have the manifest name twice in your template and it doesn't handle the generated hash in the filename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated hash will be added to the filename, since the asset_url
helper is smart enough to generate the correct digest and everything in a production environment.
This approach will also break because you may have more than one stylesheet in your HTML; for instance in one of my apps I have to split my css files up to avoid IE9 rule limit restrictions. So I have something like this:
= RailsCriticalCssServer::Rewrite.call(self,
manifest: asset_url('css_manifest.css')) do
= stylesheet_link_tag 'bootstrap'
= stylesheet_link_tag 'common'
= stylesheet_link_tag 'page_rules'
css_manifest.css
in this case is a single stylesheet with all the rules, in an easy format that criticalcss can read.
Here's a cleaned up version of the previous PR:
Some minor things:
A bit more major:
removes manifest arg and defines a method to get the current stylesheet. Basically, this was previously set up to only work with stylesheets named 'application.css' -- and it seemed, at least for me, to pass the string 'application.css' to the node server -- when in fact the file name had a hash on it - e.g. application-fab7daa9310cc448046aee95dccad8018095b572b53077b78bc4b8bc8545c5bf
I've had this branch running for a week or so now and it seems to be working well.