You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 8, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+21-42Lines changed: 21 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,13 +25,17 @@ CssSplitter integrates with the Rails 3.1+ Asset Pipeline to generate additional
25
25
26
26
The first step is identifying the stylesheets that have more than 4095 selectors and therefore need to be split for IE.
27
27
28
-
Once you know which stylesheets need to be split, you need to create a second "container file" for those stylesheets with the file extension `.split2`, that will contain the styles beyond the 4095 selector limit.
28
+
Once you know which stylesheets need to be split, you need to create a second "container file" for those stylesheets with the `_split2` suffix appended to the base filename that will contain the styles beyond the 4095 selector limit. The extension of this file should be just `.css` without any additional preprocessor extensions.
29
29
30
-
For example, if you want to split `too_big_stylesheet.css`, you need to create a new file `too_big_stylesheet_split2.css.split2` in the same directory. The only content of that container, will be an include of the original file, e.g.:
30
+
For example, if you want to split `too_big_stylesheet.css.scss`, you need to create a new file `too_big_stylesheet_split2.css` in the same directory. The only content of that container, will contain a `require` directive to the name of the original asset, e.g.:
If your stylesheet is big enough to need splitting into more than two more files, simply create additional `_split3`, `_split4`, etc. files, the contents of which should be identical to the `_split2` file.
35
39
36
40
You also need to remember to add those new files to the asset pipeline, so they will be compiled. For example:
37
41
@@ -43,12 +47,10 @@ You also need to remember to add those new files to the asset pipeline, so they
43
47
44
48
Here is a checklist of requirements for your split stylesheet:
45
49
46
-
1. It needs to have different filename than orginal, e.g. `original_stylesheet_split2` or `application_split2`
47
-
2. It needs to have `.split2` as a file extension, e.g. `.css.split2`, `.css.sass.split2`, or `.css.split2.erb`
48
-
3. It needs to include the content of the orginal stylesheet, e.g. through `//= include 'application'` or `<%= environment.find_asset('application') %>`
49
-
4. It needs to be added to list of precompiled assets
50
-
51
-
50
+
1. It needs to have the `_splitN` suffix appended to the original asset name, e.g. `original_stylesheet_split2` or `application_split2`
51
+
2. It needs to have `.css` as a file extension.
52
+
3. It needs to require the orginal stylesheet.
53
+
4. It needs to be added to list of precompiled assets.
52
54
53
55
### 2. Including your split stylesheets
54
56
@@ -60,51 +62,28 @@ You can just use our `split_stylesheet_link_tag` helper, which would look someth
Or you can just create similar HTML as in the above example yourself. If you want to use the `split_stylesheet_link_tag` helper you need to make sure the gem is loaded in production, so you can't put it in the `:assets` group in your Gemfile.
69
75
70
76
## How it works
71
77
72
-
Basically, CssSplitter is registering a new `Sprockets::Engine`for the `.split2` file extension, that will fill those files with all the selectors beyond the 4095th. Unfortunately, those `.split2` files need to be created manually, because we haven't figured out a way for a `Sprockets::Engine` to output multiple files. They need to present before the compile step.
78
+
Basically, CssSplitter is registering a new Sprockets bundle processor that looks for CSS assets named with the `_splitN` suffix and will fill those files with all the selectors beyond the 4095th. Unfortunately, those `_splitN` files need to be created manually, because we haven't figured out a way for a `Sprockets::Engine` to output multiple files. They need to present before the compile step.
73
79
74
80
If you have more questions about how it works, look at the code or contact us.
75
81
76
82
## Gotchas
77
83
78
-
#### Having a JS asset with the same name as the the split stylesheet
79
-
80
-
If you want to split a style (e.g. `assets/stylesheets/application.*`) and have a JS asset with the same name (`assets/javascripts/application.*`) in your asset load_path (as is the default in Rails), you need to include the stylesheet along with the file extension `// = include 'application.css'` because otherwise it will try to include the JS asset of the same name instead. Sprocket's `= include` directive doesn't seem to differentiate between different types/folders and just takes the first asset it can find for any given name (see #10).
81
-
82
-
#### Don't use Sprocket's `= require_tree .` or `= require_self` for stylesheets
83
-
It's recommended that you **always use Sass's `@import`** for all your stylesheets in favor of Sprocket's `= require` directives, just as the official `sass-rails` gem says: https://github.com/rails/sass-rails#important-note
84
-
85
-
If you have a `.split2` stylesheet in your tree that in turn includes the base stylesheet like shown below, you will end up with a nasty `Sprockets::CircularDependencyError`!
If you have `require_self` in the stylesheet that you're splitting, as shown below, the `.split2` will end up having **both** the original stylesheet and the split contents. You'll end up with an even bigger stylesheet.
Currently the gem only supports stylesheets that need to be split into 2 files. It could theoretically create more splits (e.g. if you should have more than 8190 selectors), but in that case you should probably refactor your stylesheets anyway. Contact us, if you have this requirement.
84
+
#### Differences from previous versions
107
85
86
+
Note that if you used the 0.x.x versions of this gem, the naming and contents of the split files have changed. Split files no longer need to have the `.split2` extension and now use the `require` directive rather than the `include` directive. The previous prohibition against using `require_tree .` and `require_self` directives also no longer applies.
0 commit comments