forked from FullHuman/purgecss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request FullHuman#42 from taylorbryant/patch-1
Fix typos & capitalization, improve grammar
- Loading branch information
Showing
1 changed file
with
11 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
# Comparison with other tools | ||
|
||
Purgecss is not the only tool to remove unused css. Below you will find a list of some of the tools available as well as a comparison with Purgecss. | ||
Purgecss is not the only tool to remove unused CSS. Below you will find a list of some of the tools available as well as a comparison with Purgecss. | ||
|
||
## Purifycss | ||
## PurifyCSS | ||
|
||
The biggest flaw with purifycss is its lack of modularity. It is also is biggest benefit, purifycss can work with any files, not just html or javascript. But purifycss works by looking at all the words in the files and comparing them with the selectors in the css. Every words is consider a selector, which means that a lot of selectors can be consider used because you have the selector name in a paragraph or somewhere in your files. | ||
The biggest flaw with PurifyCSS is its lack of modularity. However, this is also its biggest benefit. PurifyCSS can work with any file type, not just HTML or JavaScript. PurifyCSS works by looking at all of the words in your files and comparing them with the selectors in your CSS. Every word is considered a selector, which means that a lot of selectors can be erroneously consider used. For example, you may happen to have a word in a paragraph that matches a selector in your CSS. | ||
|
||
Purgecss fixes this problem by providing the possibility to create an _extractor_. An extractor is a function that takes the content of a file and extract the list of css selectors in it. It allows a perfect removal of unused css. The extractor can used a parser that returns an ast and then looks through it to select the css selectors. | ||
Purgecss fixes this problem by providing the possibility to create an _extractor_. An extractor is a function that takes the content of a file and extracts the list of CSS selectors used in it. It allows a perfect removal of unused CSS. | ||
|
||
That is the way `purge-from-html` works. You can specified which selectors you want to use for each types of files, and so, get the most accurate results. You can still use the default or the legacy extractor that will act the same way as purifycss. | ||
The extractor can be used as a parser that returns an AST (abstract syntax tree) and looks through it to find any CSS selectors. This is the way `purge-from-html` works. You can specify which selectors you want to use for each file type, allowing you to get the most accurate results. Additionally, you can use the default or legacy extractor, which will mimic PurifyCSS's behavior. | ||
|
||
## Uncss | ||
## UnCSS | ||
|
||
As indicated in its Readme, Uncss works the following way: | ||
As indicated in its Readme, UnCSS works in the following way: | ||
|
||
1. The HTML files are loaded by jsdom and JavaScript is executed. | ||
2. All the stylesheets are parsed by PostCSS. | ||
|
||
3. document.querySelector filters out selectors that are not found in the HTML files. | ||
|
||
4. The remaining rules are converted back to CSS. | ||
|
||
Because of its HTML emulation and JavaScript execution, UnCSS is effective at removing unused selectors from web applications. However, its emulation can have a cost in terms of performance and practicality. | ||
|
||
To remove unused CSS from Pug template files, for example, you would need to convert Pug to HTML and emulate the page inside jsdom. Only after this can UnCSS run `document.querySelector` on each selector and perform Step 4. | ||
|
||
Because of the emulation of html, and the execution of javascript, uncss is effective at removing unused selectors from web application. But the emulation can have a cost in term of performance and practicality. Uncss works by emulating the html files. To remove unused css from pug template files, you will need to convert pug to html and then emulate the page inside jsdom and uncss will run `document.querySelector` on each selectors and step 4. | ||
|
||
Uncss by its design is probably the most accurate tool to remove css out of a simple web application at this moment if you do not use server side rendering. | ||
At the moment, UnCSS is probably the most accurate tool to remove unused CSS if you do not use server-side rendering. | ||
|
||
Purgecss does not have an extractor right now for javascript files. But because of its modularity, developers can create an extractor for specific framework \(vue, react, aurelia\) and files \(pug, ejs\) and get the most accurate result without the need of emulation. | ||
Purgecss does not have an extractor right now for JavaScript files. But because of its modularity, developers can create an extractor for specific frameworks \(Vue, React, Aurelia\) and file types \(pug, ejs\). This way, you can get the most accurate results without the need of emulation. | ||
|
||
|
||
|