Code Monkey home page Code Monkey logo

Comments (8)

Princesseuh avatar Princesseuh commented on September 20, 2024 1

As far as I know, this is intended, compressHTML is never supposed to change the visual output of the website

from docs.

Princesseuh avatar Princesseuh commented on September 20, 2024 1

No (well it's not supposed to at least?), because spaces in this context always get collapsed to one. That's why Prettier formats

<span>
  
  
	Something
  
  
  
</span>

into

<span> Something </span>

because they end up with the same visual result, since the number of whitespace doesn't matter.

And it would be useful to still have at least an opt-in mode where all whitespace is collapsed (similar to JSX). Currently this does not seem achievable even with a Vite plugin (transformIndexHtml does not get called on Astro-generated HTML).

I agree, that'd be cool! Essentially turning the HTML into JSX, ha.

from docs.

mayank99 avatar mayank99 commented on September 20, 2024 1

Yeah, that makes sense to me. Thanks for the quick response

Edit: created discussion withastro/roadmap#868

from docs.

mayank99 avatar mayank99 commented on September 20, 2024

Isn't it already changing the visual output by removing indentation?

In any case, the current documentation is misleading.

And it would be useful to still have at least an opt-in mode where all whitespace is collapsed (similar to JSX). Currently this does not seem achievable even with a Vite plugin (transformIndexHtml does not get called on Astro-generated HTML).

from docs.

Princesseuh avatar Princesseuh commented on September 20, 2024

Moving this issue to docs, since it's a docs issue in the end. It should be documented that compressHTML only compresses HTML in lossless manner and that in order to preserve the visual of the authored HTML, it might keep some whitespaces.

from docs.

Princesseuh avatar Princesseuh commented on September 20, 2024

@mayank99 Feel free to create a roadmap discussion https://github.com/withastro/roadmap/discussions with the compressHTML idea!

from docs.

mayank99 avatar mayank99 commented on September 20, 2024

Worth also noting that the prettier plugin will sometimes forcibly insert meaningful whitespace, by breaking up long lines.

(If there was a way to trim whitespace, it wouldn't be an issue)

from docs.

sarah11918 avatar sarah11918 commented on September 20, 2024

Thanks for the discussion here!

Would be happy if someone wanted to make a PR to adjust the wording per Erika's note that

compressHTML only compresses HTML in lossless manner and that in order to preserve the visual of the authored HTML, it might keep some whitespaces.

The change must be made here (in the main astro repo):
https://github.com/withastro/astro/blob/main/packages/astro/src/%40types/astro.ts#L721

And maybe update the content to something like:

This is an option to minify your HTML output and reduce the size of your HTML files. Astro removes whitespace from your HTML, including line breaks, from .astro components in a lossless manner. This means that some whitespace may be kept to preserve the visual rendering of your HTML. This occurs both in development mode and in the final build. To disable HTML compression, set the compressHTML flag to false.

from docs.

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.