Sunday, 28 February 2021

Template literals/strings with \n and spaces compiled by closure compiler

Some pieces of HTML are injected in the DOM by one of our js library compiled by Closure Compiler.

We use template literals/strings to dynamically change the HTML and also to ease maintenance by keeping indented HTML in our js files.

Unfortunately, it means that our minified file contains a lot of useless '\n' and spaces in the strings corresponding to these template literals (no surprise, this is as per ES6)

Is there a way to not have all the useless \n and spaces in the minified file?

Example of source code:

this.root.append(`
  <div>
    <a href="#">
      <span>${someText}</span>
    </a>
    <div class="dialog"></div>
  </div>`);

The corresponding compiled code looks like:

...;this.h.append("\n  <div>\n    <a href="#">\n      <span>"+z+"</span>\n    </a>\n    <div class="dialog"></div>\n  </div>");...


from Template literals/strings with \n and spaces compiled by closure compiler

No comments:

Post a Comment