<commit_before># critical-path-css-rails [![Code Climate](https://codeclimate.com/github/mudbugmedia/critical-path-css-rails/badges/gpa.svg)](https://codeclimate.com/github/mudbugmedia/critical-path-css-rails)

Only load the CSS you need for the initial viewport in Rails!

This gem give you the ability to load only the CSS you *need* on an initial page view. This gives you blazin' fast rending as there's no initial network call to grab your application's CSS.

This gem assumes that you'll load the rest of the CSS asyncronously. At the moment, the suggested way is to use the [loadcss-rails](https://github.com/michael-misshore/loadcss-rails) gem.

This gem uses [PhantomJS](https://github.com/colszowka/phantomjs-gem) and [Penthouse](https://github.com/pocketjoso/penthouse) to generate the critical CSS.


## Installation

Add `critical-path-css-rails` to your Gemfile:

```
gem 'critical-path-css-rails', '~> 0.2.0'
```

Download and install by running:

```
bundle install
```

Run the generator to install the rake task and configuration file:

```
rails generator critical_path_css:install
```

The generator adds the following files:

* `config/critical_path_css.yml`
* `lib/tasks/critical_path_css.rake`


## Usage

First, you'll need to configue a few things in the YAML file: `config/critical_path_css.yml`

* `manifest_name`: If you're using the asset pipeline, add the manifest name.
* `css_path`: If you're not using the asset pipeline, you'll need to define the path to the application's main CSS. The gem assumes your CSS lives in `RAILS_ROOT/public`. If your main CSS file is in `RAILS_ROOT/public/assets/main.css`, you would set the variable to `/assets/main.css`.<commit_msg>Fix typo in README.md<commit_after># critical-path-css-rails [![Code Climate](https://codeclimate.com/github/mudbugmedia/critical-path-css-rails/badges/gpa.svg)](https://codeclimate.com/github/mudbugmedia/critical-path-css-rails)

Only load the CSS you need for the initial viewport in Rails!

This gem give you the ability to load only the CSS you *need* on an initial page view. This gives you blazin' fast rending as there's no initial network call to grab your application's CSS.

This gem assumes that you'll load the rest of the CSS asyncronously. At the moment, the suggested way is to use the [loadcss-rails](https://github.com/michael-misshore/loadcss-rails) gem.

This gem uses [PhantomJS](https://github.com/colszowka/phantomjs-gem) and [Penthouse](https://github.com/pocketjoso/penthouse) to generate the critical CSS.


## Installation

Add `critical-path-css-rails` to your Gemfile:

```
gem 'critical-path-css-rails', '~> 0.2.0'
```

Download and install by running:

```
bundle install
```

Run the generator to install the rake task and configuration file:

```
rails generate critical_path_css:install
```

The generator adds the following files:

* `config/critical_path_css.yml`
* `lib/tasks/critical_path_css.rake`


## Usage

First, you'll need to configue a few things in the YAML file: `config/critical_path_css.yml`

* `manifest_name`: If you're using the asset pipeline, add the manifest name.
* `css_path`: If you're not using the asset pipeline, you'll need to define the path to the application's main CSS. The gem assumes your CSS lives in `RAILS_ROOT/public`. If your main CSS file is in `RAILS_ROOT/public/assets/main.css`, you would set the variable to `/assets/main.css`.
{'fraction_non_alphanumeric': 0.10667058477813694, 'fraction_numerical': 0.001763150161622098, 'mean_word_length': 4.701842546063651, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6825721', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1027, 'n_words': 384}