Code Monkey home page Code Monkey logo

Comments (11)

tomayac avatar tomayac commented on August 12, 2024 1

Is [:host([hidden]) {…}] necessary?

Yes, it's a best practice.

from dark-mode-toggle.

tomayac avatar tomayac commented on August 12, 2024 1

You don't just want minify-template-strings (i.e. just removing whitespace), you want minify-css-in-template-strings. I don't know of an existing tool that does this.

Eagerly awaiting CSS modules that will make this so much better.

from dark-mode-toggle.

mathiasbynens avatar mathiasbynens commented on August 12, 2024

You don't just want minify-template-strings (i.e. just removing whitespace), you want minify-css-in-template-strings. I don't know of an existing tool that does this.

Some other ideas to reduce minified bundle size: #11

from dark-mode-toggle.

mathiasbynens avatar mathiasbynens commented on August 12, 2024

Is this necessary?

:host([hidden]) {
  display: none;
}

I thought this was the default but am likely missing something.

from dark-mode-toggle.

mathiasbynens avatar mathiasbynens commented on August 12, 2024

Another thing that jumps out is this. occurs more than 150 times in the minified source. We could largely reduce that number by doing something like const _this = this; at the top of the constructor. _this can then be minified just like any other identifier.

Although this likely wouldn't reduce the gzip/brotli size, it would reduce the number of bytes that need to be parsed and compiled.

from dark-mode-toggle.

mathiasbynens avatar mathiasbynens commented on August 12, 2024

You don't just want minify-template-strings (i.e. just removing whitespace), you want minify-css-in-template-strings. I don't know of an existing tool that does this.

Eagerly awaiting CSS modules that will make this so much better.

We could hack something together ourselves. The template literal's contents would be stored in a separate source file in the repository, and processed by a custom script that strips whitespace and applies some simple CSS optimizations. The result would then be injected as a template literal into the built .js file. The downside is that the source *.js file would no longer be useful for testing; you'd have to create a build just to get a working file. It's definitely a trade-off... Maybe it's worth it though.

Happy to prototype this if this doesn't sound too horrible to you.

from dark-mode-toggle.

tomayac avatar tomayac commented on August 12, 2024

We could hack something together ourselves.

Sure, but at this point you'd build a build system. I really preferred if we instead chimed in on making CSS Modules a thing rather sooner than later. If you could review their proposal and comment on it, this would be a better use of your brain in my opinion.

from dark-mode-toggle.

tomayac avatar tomayac commented on August 12, 2024

We could largely reduce that number by doing something like const _this = this; at the top of the constructor. _this can then be minified just like any other identifier.

Great idea, thanks. Could you add this to your PR? You can test the changes by running npm run start and navigating to http://localhost:8080/demo (you have probably figured this out, but just thought I'd point it out). Will add this to the README as well.

from dark-mode-toggle.

mathiasbynens avatar mathiasbynens commented on August 12, 2024

Great idea, thanks. Could you add this to your PR?

Tried it, but turns out not to save anything: #11 (comment) So didn't add it to the PR.

Thanks for the pointer, I have been testing the changes!

from dark-mode-toggle.

tomayac avatar tomayac commented on August 12, 2024

Also added the instructions to the README.

from dark-mode-toggle.

tomayac avatar tomayac commented on August 12, 2024

Closed via #11. 🎉

from dark-mode-toggle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.