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

Fixes #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Fixes #2

wants to merge 4 commits into from

Conversation

josh-m-sharpe
Copy link

Here's a cleaned up version of the previous PR:

Some minor things:

  1. eases the dependency on httparty
  2. Fixes ErrorHandler to properly use Callable module.

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.

@@ -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)
Copy link
Owner

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

Copy link
Author

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.

Copy link
Owner

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.

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.

None yet

2 participants