2

The resulting static html code from gatsby-image is something like this:

<div class=" gatsby-image-wrapper" style="position: relative; overflow: hidden;">
    <!-- Placeholder here (removed for abreviation)... -->
    <picture>
        <!-- Image tag and `sources` here... -->
    </picture>

    <!-- ⚠ This is what I want to remove ⚠ -->
    <noscript>
        <picture>
            <!-- Image tag and `sources` here... -->
        </picture>
    </noscript>
    <!-- ⚠ This is what I want to remove ⚠ -->

</div>

I couldn't find an option to <noscript> in the docs.

This is the image component:

import * as React from "react"
import { StaticQuery, graphql } from "gatsby"
import Img from "gatsby-image"
const MyPhoto = () => (
  <StaticQuery
    query={graphql`
      query {
        placeholderImage: file(relativePath: { eq: "image.png" }) {
          childImageSharp {
            fluid(maxWidth: 160) {
              ...GatsbyImageSharpFluid_withWebp
            }
          }
        }
      }
    `}
    render={data => <Img  loading="eager" fluid={data.placeholderImage.childImageSharp.fluid} />}
  />
)
export default MyPhoto

Pretty much the default that comes with this starter template: gatsby-starter-typescript-jest.

This is the gatsby-config.js, I've removed some unecessary comments and properties:

module.exports = {
  plugins: [
    `gatsby-plugin-preact`,
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {...myManifestOptions},
    },
    `gatsby-plugin-typescript`,
  ],
}

The reason is that I just don't want to add support for disabled javascript.

Rick Stanley
  • 732
  • 2
  • 9
  • 23
  • short answer: don't. Leave it, it's not causing any problems, you are in no way expected to fill it in, just move on and focus on real work instead. JS is so pervasive that no _serious_ indexer is going to index your page without running scripts. – Mike 'Pomax' Kamermans Jan 10 '21 at 00:02
  • except it's an irrelevant amount of bytes. Don't micro-optimize if there's _any_ other work left to do. the 100 bytes (if even that) saved are _meaningless_ compared to even a single image or JS function (not even js file, just a single function). You don't need this tag, sure, but it's so tiny that ignoring it is the right thing to do, because it has _no_ impact on anything compared to everything else else you've written. Not even extreme low bandwidth mobile users feel the number of bytes involved here. Optimize _literally everything else_ first. – Mike 'Pomax' Kamermans Jan 10 '21 at 00:35
  • It is, but "don't bother" is an equally fair answer. Know what's worth spending time on. This isn't. – Mike 'Pomax' Kamermans Jan 10 '21 at 02:22

1 Answers1

0

You can't remove that <noscript> behavior since it's inherent by default gatsby-image and it doesn't add any kind of customization to avoid it.

As it has been said by @Mike 'Pomxa' Mamermans it's strongly suggested to leave it. It's not a matter of "I just don't want to add support for disabled javascript", it's a matter of default fallback for old browsers or browsers that have the JavaScript disabled, and trying to change this behavior will thrive you in weird caveats since you will need to change the package functionality itself from node_modules so your change won't be persistent.

If you want to add this behavior you'll need to add a PR to Gatsby's repository providing a solution for your use-case since what you are trying to achieve by removing the <noscript> tag it's not intended behavior for gatsby-image.

It also doesn't make sense to remove functionality that potentially will make your site reach more people at default cost, in a meaningless amount of bytes that those lines add.

Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
  • 2
    Thanks. I just wanted to know if I could have more control over the default settings, noscript is irrelevant for this project and I rather just not use it at all. I've trimmed as many useless code from gatsbt as could (e.g. changed from React to preact, no-javascript plugin, etc). I think it does makes sense in some cases. – Rick Stanley Jan 10 '21 at 12:08