eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

Edge plugin: Issue with HTML Minification and Eleventy Edge

Open saneef opened this issue 2 years ago • 8 comments

Many minifies HTML, likely removing HTML comments from the generated files. This will break Edge plugin since it relies on HTML comments to replace the content.

We should mention that the user should be mindful about the HTML comments.

saneef avatar Jun 11 '22 19:06 saneef

See #2409, Like me others also wondering suddenly Edge plugin don't work on Netlify!

saneef avatar Jun 11 '22 20:06 saneef

Yes absolutely. What minifier are you using?

zachleat avatar Jun 15 '22 13:06 zachleat

I'm using html-minifier, following @hankchizljaw's tutorial.

saneef avatar Jun 15 '22 14:06 saneef

I wonder if also an option to wrap with a custom identifier would be good.

In your case <!-- htmlmin:ignore --> https://github.com/kangax/html-minifier#ignoring-chunks-of-markup

image https://kangax.github.io/html-minifier/

zachleat avatar Jun 15 '22 14:06 zachleat

Thanks a lot for that tip!

I hadn't dig through html-minifier docs. My bad.

See my hack 🤢:

<!DOCTYPE html>
{% edge "njk" %}<html dir="ltr" lang="en" data-user-color-scheme="{{ eleventy.edge.cookies.appearance | default("auto", true) }}">{% endedge %}
{% edge "njk" %}{{"<!--" | safe}}{% endedge %}
<html dir="ltr" lang="en">
{% edge "njk" %}{{"-->" | safe}}{% endedge %}

  ...
</html>

saneef avatar Jun 15 '22 14:06 saneef

I think the other thing that’s warranted here is a one-off build time warning that checks one output file (using {% edge %}) post-build to make sure the Edge comments exist. If not, throw an error message

zachleat avatar Jun 15 '22 20:06 zachleat

Related https://github.com/11ty/eleventy/discussions/2409 and https://github.com/11ty/eleventy/issues/2399

zachleat avatar Jun 15 '22 21:06 zachleat

Thanks a lot for that tip!

I hadn't dig through html-minifier docs. My bad.

See my hack 🤢:

<!DOCTYPE html>
{% edge "njk" %}<html dir="ltr" lang="en" data-user-color-scheme="{{ eleventy.edge.cookies.appearance | default("auto", true) }}">{% endedge %}
{% edge "njk" %}{{"<!--" | safe}}{% endedge %}
<html dir="ltr" lang="en">
{% edge "njk" %}{{"-->" | safe}}{% endedge %}

  ...
</html>

Sorry, this hack was made to populate the value of data attribute using Edge function. The result I wanted was :

<html dir="ltr" lang="en" data-user-color-scheme="auto">

It looks to me the <html ...> tag generated by the example Dark toggle generates an invalid markup. The generated <html> tag end up like:

<!DOCTYPE html>
<html lang="en"<!--ELEVENTYEDGE_edge "liquid" %} class="theme-{{ elev enty.edge.cookies.appearance | default: "auto" | escape }}"ELEVENTYED GE_edge-->>

The comment inside the <html ... > tag breaks some HTML parsers. In my, case a couple of plugins which use Cheerio corrupts the generated page. So I end up writing the above hack to generate the markup I need.

saneef avatar Jun 16 '22 17:06 saneef

Hey, I've stumbled over this thread as I had the same problem. I've solved it by removing removeComments: true, from the options of html-minifier.

schneyra avatar Nov 17 '22 21:11 schneyra

Per the Eleventy Community Survey results and our refocus and prioritization towards our roots as a static site generator, we’re going to be deprecating Edge in 3.0 and closing issues related to the Edge plugin. I’m very sorry to have to do this—but unfortunately this was a necessary decision to allow the project to continue forward.

Read more: https://www.zachleat.com/web/eleventy-side-project/ https://www.11ty.dev/blog/community-survey-results/

zachleat avatar Nov 11 '23 04:11 zachleat