The official page for all that concerns the development of rmrf-css
Road
Road
map
Ideation
It began with the inadequacy of existitng tools like PurgeCSSTMas blogged by Chris Coyier on CSS Tricks, etcetera, in detecting likely used CSS selectors wherever they may be while avoiding the actual content in the markup of a page
for all the pages of the website below
Done in
<N> ms
After multiple iterations, much more efficient performance was obtained which made this service viable as an alternative to software for trimming used CSS
• Trimming the stylesheets of a site built for a construction company
Stylesheets lesser than 1 MB took milliseconds but the TailwindCSS stylesheet made the Node.js code sweat a little however, a performant and non CPU-intensive solution sufficed
Development
Hardcoding of CSS functions, selectors, selector wildcards, @-rules etc., into the code was avoided because they may change as the W3C specification evolves.
hardcoding CSS functions, selectors like where() is one of the shortcomings of the existing software for removing unused CSS
A summary of the final draft of the algorithm used to get the style block of used CSS selectors
whatever-style-entity [# or .]
if it is an element in [the array of likely CSS selectors]
used-CSS-selector
if not a [string, number or whitespace]
extra style entity {/*this style block is added to the string of matched styles if the conditions [hover over the hilighted text to see them] above are true*/}
Edge case
• Selectors that start with a number or contain illegal characters such as:[, ], :, &, >, *, / are escaped by adding a reverse solidus to them as follows: \[, \], \:, \&, \>, \*, \/
Comments - to be or not to be...
The algorithm originally, while detecting used selectors, stripped comments from the stylesheet including nefarious ones that even broke the parsing of CSS in browsers like this: sele/*parse breaking comment*/ctor { ... }
This extra consideration caused faulty performance as the code evolved. If it is ever to be considered, the removal of comments will come first before the actual matching and trimming happens.
the functionality for removing comments will be provided behind a flag in the future releases of this service
Quirks & Solutions
#1 A frustrating quirk, not a bug, in Node.js happens when matching used style blocks in files of over 1MB in size like the TailwindCSSstylesheet ↴
for(•••){/* this regular for loop begins to increment slowly as though it is a much-delayed setTimeout callback*/}
reducing the number of selectors to match did not abate this development...hiatus...
(ಥ _ ಥ) "days of frustration..."
Moreso, this line of code in the loop: index&&index/20000 === Math.round(index/20000)&&console.log('::INDEX::', index)took over 10 seconds to log an output of a multiple of 2000
The solution to this quirk came from the insight that worded this comment above - "/* this regular for loop begins to increment slowly as though it is a much-delayed setTimeout callback*/"
Wrapping the regular for loop in the code with a lifecycle method in Node.js like process.nextTick, setTimeout or setImmediate fixed this quirk that seems to stem from an event-loop-blocking cause
setImmediate performed the fastest and thus was used with the for loop with a variable number of iterations to increase throughput of the code without slowdowns. The client-side equivalent of setImmediate - requestAnimationFrame is used in the client-side version of the code
Goalsrmrf-css@v0.0.1
Goals
Goals
A major goal is to make this service into a full-fledged SaaS using a subscription-based business model with support for freemium as well as paid support for teams and brands(enterprises)
Freemium
A website built around the service with user account creation provided
Flags to consider or ignore @-rules and/or comments
Execution of scripts present on the website that may further modify the CSSOM or DOM before beginning to remove its unused styles
Option to remove unused style blocks with selectors that start with a '#' or a '.' in order to leave generic CSS selectors like section > p:nth-of-type(2n) alone
Interactive display of each element or section in HTML file with its corresponding selectors used to paint it
Infovisuals such as histograms for a quick surmise of the classes matched and unmatched
Limited
Automation via a provided GitHub repository to routinely clone and trim the stylesheets used in specified HTML files as a sort of support for CI/CD
Limited
POST the result of the trimmed stylesheets to a provided URL endpoint in a predefined manner.
$
Interactively fetch all webpages linked to in a website along with their stylesheets and generate used styles for the entire website at once
$
Previews of the result of the trimmed stylesheets by using them in a duplicate of the provided website
Products
rmrf-css
Remove unused CSS from the stylesheets used on websites, thoroughly... check it out
brainstorming...
Partially done, will complete and defer its release and integration till the freemium milestone for rmrf-css is reached
TokenizeCSS • idea
TokenizeCSS scans stylesheets for matches of user-provided property names or values in CSS for the purpose of detecting patterns in their values that can then be used to generate new stylesheets based on ratios, progressions etc., that are computed or provided by the user
The stylesheet for darkmode
can be quickly generated, for example, by matching all properties containing "color" - background-color, color, border-color; the results of which can then be tweaked using JavaScript to quickly get an inversion of the "color"s
Design systems and design tokens
can be used, created and modified from setting constraints for and modifying the values of matched CSS properties in a given order like the ratios used in typographic scales for example.
Why three ideas even when the third is not yet concieved? It's because:
"If one, it might corrupt, if two, they may divide but if three, they will unite^_~"
Workarounds
Client-side requests for linked assets - scripts, stylesheets may fail due to CORS whereby the server doesn't set this header in its response as follows: 'Access-Control-Allow-Origin': '*'
Making these requests on the server however overcomes this limitation. Implementing this workaround will be easier when user accounts - the freemium model is launched; it is deferred until then...
Coming soon...
#1
Ultra fast
• The quickest option among the options for increasing the speed of the CSS trimming operation. Web workers will be used to provide support for this speed option in time
#2 Functionality to create and support uploading a rem-css.config.json file that can be used to tweak or hasten the flow of the service to suit one's needs.