terser VS critical

Compare terser vs critical and see what are their differences.

terser

🗜 JavaScript parser, mangler and compressor toolkit for ES6+ (by terser)
Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
terser critical
27 11
8,402 9,950
1.2% -
8.9 7.1
16 days ago 20 days ago
JavaScript JavaScript
GNU General Public License v3.0 or later Apache License 2.0
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

terser

Posts with mentions or reviews of terser. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-10-18.

critical

Posts with mentions or reviews of critical. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2024-04-11.
  • Enhance WASM: Back End Agnostic SSR for Web Components
    4 projects | news.ycombinator.com | 11 Apr 2024
    If the link element is placed inside of the shadow DOM, then it's not render blocking and you will experience a flash of unstyled content. That's what the lit docs are referring to.

    If you place the link element inside the head of your document, then it is render blocking, which means the browser has to make two round trips to the server if the CSS file isn't in the cache before it render (one to download the HTML file, and then another after it discovers your link element, and has to download the corresponding CSS file).

    > The best from both worlds is to embed a lightweight basic CSS stylesheet inline and the rest in cache-able external CSS files.

    This is the absolute optimal way of doing it. You would have to analyze your styles to see which styles are applied to elements above the fold, then extract them and put them in an inline style tag. The rest of the styles would have to be downloaded via a link tag, but you'd have to place the link tag at the very end of the HTML body tag to prevent the browser from blocking as soon as it encounters the link element or alternatively use JavaScript to add the link element after the page has been rendered. There are tools to automate this for static sites [1], but doing this for dynamically generated HTML is kind of a pain, and I've found that browsers parse CSS so quickly that the overhead of just inlining it all is very low in many cases.

    [1] https://github.com/addyosmani/critical

  • Frontend developers: stop moving things that I’m about to click on
    3 projects | /r/programming | 25 Nov 2022
    CLS is a pain in the arse. Extract your critical CSS and inline it https://github.com/addyosmani/critical although doing critical CSS badly makes things worse.
  • Critical – Extract and Inline Critical-Path CSS in HTML Pages
    1 project | news.ycombinator.com | 11 Nov 2022
  • Google Page Speed Insights and Magento 2
    2 projects | dev.to | 7 Nov 2022
    There is a tool that allows generating critical CSS and determining which CSS is critical and which is not. It helps to separate it into files, and there is also an npm package for that.
  • Critical CSS? Not So Fast
    5 projects | news.ycombinator.com | 10 Sep 2022
    I am a fan of CSSWizardry and yet I find this post misleading. The examples shown are ways NOT to do frontend performance engineering.

    The current best performant way to load JS is asynchronously as documented at https://web.dev/efficiently-load-third-party-javascript/.

    And the best way to load CSS is with Critical Path CSS + Async CSS as documented at https://web.dev/defer-non-critical-css/.

    The easiest way to generate Critical CSS is https://github.com/addyosmani/critical where you may suggest multiple resolutions.

    I have found https://github.com/addyosmani/critical-path-css-tools to be a great resource to master critical path CSS which improves page render speeds. It helps build fast rendering sites, sometimes even sub-second renders given you have a low latency backend.

  • How to Make Your Page Load Faster
    1 project | dev.to | 1 Sep 2022
    CSSOM tree has to be built before start rendering the page. To build it, the browser has to parse the CSS first. I said parse and not load because your CSS can be inlined (in a tag).

    CSS is render-blocking, which means you can't start rendering the page until it's parsed. But it's not parser-blocking, which means the browser can continue parsing the HTML while the CSS is being downloaded (if it was linked externally).

    The main takeaway here is that the larger your CSS file is the longer it will take to start rendering the page because it's a render-blocking resource.

    Loading JavaScript

    JavaScript is a parser-blocking resource. This means once the browser finds any JavaScript code, it will stop parsing immediately to download and execute the JavaScript. After the JavaScript is executed, the parser can continue parsing the document.

    So JavaScript can delay rendering because the browser can't complete building the DOM until it has parsed the HTML.

    JavaScript has to wait for CSSOM

    To make things even worse, your JavaScript code can't start executing if there's CSS being downloaded. In other words, if you have Optimizing your page load time

    Now we get to the fun part; making our pages load faster.

    Getting into the details of each technique is beyond the scope of this article, but I will give you a quick overview of each one. After that, it should be easier to learn more about each one on your own.

    Only load the used/critical CSS

    Most of the time we load CSS that we don't need in the current page. So, we can split the CSS file into smaller ones and use each one based on what the current page needs.

    A common case we can apply this to is loading some third party CSS code only in the pages that need them. For example, only use the code syntax highlighter CSS library on the pages that display code.

    There's also a well-known technique called critical CSS. It's used to load only the CSS code that you see above the fold (the visible part of the browser on the initial load), and then lazy-load the rest asynchronously. And you can make this even better by inlining the critical CSS and lazy-load the rest externally.

    Loading JavaScript asynchronously

    Two popular attributes to achieve this: defer and async. Using either will not cause the browser to wait until they are downloaded to continue parsing.

    The main difference between them is the time and order of execution.

    Defer scripts start executing after the whole DOM is constructed but before DOMContentLoaded event is fired. This also means you should see the page rendered before executing the script.

    Defer scripts execute in the order they were defined. So if script1 is above script2, script1 will always start executing before script2 even if script2 is loaded before.

    Async scripts will start execute as soon as they are fetched. Async scripts don't wait for the DOM to be constructed, which means they can block the parser if an async script is fetched before the DOM is built.

    Async scripts execute in the order they were fetched. The one that loads first executes first.

    The rule of thumb is to use defer scripts when they depend on the content (DOM) of the page, and use async scripts for things that don't need the DOM such as analytics, etc.

    Minify and compress resources

    There are many build tools that help you minify your CSS and JavaScript. Minification is the process of removing any unnecessary characters for execution like spaces, comments, etc.

    Compressing your resources is done by the server. gzip and brotli and the most popular compression types nowadays.

    Minifying and compressing your resources will make them much smaller, which will improve your loading time.

    Preloading important resources

    The browser fetches the resources as it finds them while parsing the HTML. Sometimes it would be useful if we request these resource as soon as possible even before the parser finds them.

    An example would be having two synchronous external JavaScript files below each other. If we don't use preload, then we have to wait for the first script to load and execute before loading the second one. But with preload we can tell the browser to fetch that second script even while it's parsing the HTML.

    Preloading is also used for fetching other resources like CSS, images, fonts, etc.

    Preloading can be done with . Example:

     rel="preload" href="style.css" as="style">
     rel="preload" href="main.js" as="script">
    
    Enter fullscreen mode Exit fullscreen mode

    Reduce your server response time

    No matter how many optimization you do to your client code, it will not make your page load faster if your server takes a long time to send the requested HTML code.

    Usually this is the least we can control especially if we don't maintain the backend code. But if we do, we can do things like optimizing the database queries (how fast we pull data from our database), using caching, compressing and minifying responses, upgrading the server hardware, etc.

    Now you can learn more

    In this article we barely scratched the surface of loading performance optimizations. But it should be easier now to dive deeper into each one as you should have a full understanding of how the browser loads pages.

    An important part we didn't touch in this article is the tools we can use to measure the performance of the page and the impact of the optimizations we do. Google Chrome provides us with two good tools for this: the performance tab in the devtools and Lighthouse. So I encourage you to check them on your own.

  • Using Vite with Critical CSS in a way that supports users with JavaScript disabled or unavailable
    2 projects | dev.to | 28 Apr 2022
    A while ago I'd noticed that the version (or configuration) of the Critical packaged used by my Netlify build plugin was missing that fallback, so I manually added it to my Eleventy template, no big deal.
  • 3 tips that improve landing page speed
    2 projects | /r/SaaS | 28 May 2021
    Defer or async css/js files — Don’t make leads wait for unnecessary files to download before showing something. In the case of CSS, there are a few tools for in-lining only what’s above-the-fold into your html.
  • My web performance journey with Nuxt, Storyblok & Netlify
    8 projects | dev.to | 17 Apr 2021
    Consider automating the process of extracting and inlining "Above the Fold" CSS using the Critical tool.
  • Force include classes in critical CSS
    2 projects | dev.to | 21 Jan 2021
    Critical CSS build by Addy Osmani is a useful library that extracts and inlines critical-path CSS in HTML pages.

What are some alternatives?

When comparing terser and critical you can also consider the following projects:

esbuild - An extremely fast bundler for the web

penthouse - Generate critical css for your web pages

vite - Next generation frontend tooling. It's fast!

Nuxt.js - Nuxt is an intuitive and extendable way to create type-safe, performant and production-grade full-stack web apps and websites with Vue 3. [Moved to: https://github.com/nuxt/nuxt]

UglifyJS2 - JavaScript parser / mangler / compressor / beautifier toolkit

purgecss - Remove unused CSS

closure-compiler - A JavaScript checker and optimizer.

lighthouse - Automated auditing, performance metrics, and best practices for the web.

Sass - Sass makes CSS fun!

lite-youtube-embed - A faster youtube embed.

PostCSS - Transforming styles with JS plugins

vue-lazyload - A Vue.js plugin for lazyload your Image or Component in your application.