question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Large numbers of css declarations balloon js output file size.

See original GitHub issue

It appears that the use of @inline in scalacss can cause unregulated growth. I have an (unfortunately proprietary) project that I’m attempting to optimize. It contains a large number (33) of instances of StyleSheet.Inline, with a total of 109 uses of style. Compilation size (due to many factors which I’m currently investigating), is at 2.7mb.

A serious culprit visible while eyeballing fastOptJS output is inline expansion of a loop somewhere in the style definitions:

var x$58 = $as_Lscalacss_AVs(jsx$143);
  $m_Lscalacss_StyleS$();
  var c$29 = $m_Lscalacss_Cond$().empty$1;
  var d$27 = new $c_sci_Map$Map1().init___O__O(c$29, x$58);
  var this$431 = $m_s_package$().Vector$1;
  var jsx$146 = this$431.NIL$6;
  var jsx$145 = $m_s_None$();
  var this$432 = $m_s_package$().Vector$1;
  var jsx$144 = this$432.NIL$6;
  var this$433 = $m_s_package$().Vector$1;
  var jsx$142 = new $c_Lscalacss_DslBase$ToStyle().init___Lscalacss_StyleS(new $c_Lscalacss_StyleS().init___sci_Map__sci_Vector__s_Option__sci_Vector__sci_Vector(d$27, jsx$146, jsx$145, jsx$144, this$433.NIL$6));
  this.dsl__Lscalacss_mutable_StyleSheet$Base$dsl$();
  this.dsl__Lscalacss_mutable_StyleSheet$Base$dsl$();
  var this$435 = $m_Lscalacss_Attrs$cursor$();
  var x$59 = new $c_Lscalacss_AV().init___Lscalacss_Attr__T(this$435.attr$2, "pointer");
  var this$437 = $m_Lscalacss_AVs$();
  var array$32 = [];
  var this$438 = this$437.apply__Lscalacss_Attr__T__Lscalacss_AVs(x$59.attr$1, x$59.value$1);
  var start$30 = 0;
  var end$30 = $uI(array$32.length);
  var z$30 = this$438;
  x$30: {
    var jsx$138;
    _foldl$30: while (true) {
      if ((start$30 === end$30)) {
        var jsx$138 = z$30;
        break x$30
      } else {
        var temp$start$30 = ((1 + start$30) | 0);
        var arg1$36 = z$30;
        var index$34 = start$30;
        var arg2$30 = array$32[index$34];
        var x$1$43 = $as_Lscalacss_AVs(arg1$36);
        var x$2$28 = $as_Lscalacss_AV(arg2$30);
        var temp$z$30 = x$1$43.add__Lscalacss_Attr__T__Lscalacss_AVs(x$2$28.attr$1, x$2$28.value$1);
        start$30 = temp$start$30;
        z$30 = temp$z$30;
        continue _foldl$30
      }
    }
  };

The string class__defaults__Lscalacss_Defaults__Lscalacss_IDefaults occurs 669 times in this output.

Disabling all scalajs optimizations with scalaJSOptimizerOptions ~= { _.withDisableOptimizer(true) } reduces the file size by ~700kb and now class__defaults__Lscalacss_Defaults__Lscalacss_IDefaults only appears twice.

This happens to be scalacss 0.3.0, so my next step will be migrating scalacss and scalajs-react to at least get us to the latest release, but I’m fairly confident given the amount of @inlines in the codebase that this is still an issue.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
mseddoncommented, May 1, 2016

That sounds about right, in fact keeping the forwarders may even shave off a few more kilobytes 😃 If I find the time I’ll try to send a PR sometime next week, unless someone else beats me to it.

0reactions
mseddoncommented, Jun 8, 2016

Oh hey- sorry I’ve been really snowed under recently, so didn’t have a chance to put that fix together- the changes you made look like they address the real areas where I see the inlines explode. Sadly to test it with our project, we’d need to upgrade scalacss, and scalajs-react. Once this is done, I’ll re-test and see how well it works, but for now, I’m happy to close- thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Limit the size of a file upload (html input element)
I am running on Rails, not PHP, but was thinking it'd be much simpler to do it client side in the HTML/CSS, or...
Read more >
How we reduced our initial JS/CSS size by 67% - Blog - Fider
We have been working on reducing the amount of bytes that we send to all Fider users. Being a web application built with...
Read more >
Lots of Ways to Use Math.random() in JavaScript - CSS-Tricks
First, we randomly calculate the size of chord to use. Say that we got a 2 . We would then randomly select a...
Read more >
Reduce HTML5 file size - Studio Help
The size of the Enabler script is 25 KB (compressed) and 75 KB (raw). See the IAB and Studio guidelines for additional details:...
Read more >
HTML and CSS for Python Developers
In this tutorial, you'll learn how to: Structure a basic HTML file; View and inspect HTML in your browser; Insert images and page...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found