Problem/Motivation

We are working to add an empty img element inside the picture element in issue #2220865: Add empty img element inside picture element to match up with the current version of the picture specification, and to ensure that the img displayed by the picture element (once supported by browsers) has a proper alt attribute.

Once that change is made, we will have another issue, which is detailed in an issue related to the refactoring of the polyfill for the picture element, Picturefill: https://github.com/ResponsiveImagesCG/picture-element/issues/131

The problem is that for those who are using a browser that supports picture, but have JavaScript disabled, they will get two copies of the image downloaded and displayed, which is really bad.

It's important to note that research (https://gds.blog.gov.uk/2013/10/21/how-many-people-are-missing-out-on-ja...) shows that noscript only works when JS is disabled in the browser, which is about 0.2% of traffic. If JS is enabled but not working, noscript doesn't do anything: that's a much larger percentage, about 0.9% of traffic.

So right now noscript provides a benefit to a small number of people: the 0.2% of traffic where JS is disabled in the browser. As browsers start to implement picture support, though, noscript will become a real problem for those people, as it will cause them to see two copies of an image. A better solution is to drop noscript from our markup. That means that 0.2% of traffic will see alt text instead of an image, but that's probably better than getting two copies of an images downloaded and displayed, which slows down page rendering time and screws up the layout.

Proposed resolution

Remove noscript from our markup for the picture element.

Remaining tasks

- Modify markup to remove noscript element
- Remove supporting functions that generate the fallback image in the noscript element
- Modify tests to no longer check for the noscript element or fallback image.

User interface changes

Initially, the 0.2% of site traffic that actually has JavaScript disabled will see alt text rather than an image. However once picture is supported, that is a better option than the alternative, which is that those who have JavaScript disabled in browser that supports picture would see two copies of the same image.

API changes

Once #2220865: Add empty img element inside picture element is committed, our markup would look like this:

<picture>
  <source media="some media query" src="some-image.jpg" />
  <source media="some other media query" src="some-other-image.jpg" />
  <noscript><img src="fallback-image-for-no-js.jpg" alt="Awesome image" title="Awesome image" />
  <img alt="Awesome image" title="Awesome image" />
</picture>

This issue would change that markup to:

<picture>
  <source media="some media query" src="some-image.jpg" />
  <source media="some other media query" src="some-other-image.jpg" />
  <img alt="Awesome image" title="Awesome image" />
</picture>
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RainbowArray’s picture

Status: Active » Postponed

We can work on an initial patch, but it will be a lot easier to do so once #2220865: Add empty img element inside picture element goes in.

mariancalinro’s picture

Assigned: Unassigned » mariancalinro
RainbowArray’s picture

I started working on this patch before I saw the assignment from mariancalinro, so if I'm duplicating your work, my apologies.

This removes the noscript element. Right now there's a test that checks for noscript, and I removed that as well.

mariancalinro’s picture

Assigned: mariancalinro » Unassigned
Status: Postponed » Needs review
FileSize
3.42 KB

I removed the noscript and rewrote the test.

RainbowArray’s picture

This looks really good to me. We'll see what Testbot says!

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @mdrummond and @mariancalinro.

This does exactly as it sets out and replaces the tests of <noscript><img> with the fallback <source>. Thanks for the doc block fix too of that missing variable.

The 0.2% who view picture elements with js turned off can suffer by looking at alt tags until the picture element comes out!

The last submitted patch, 3: picture-remove-noscript-2227435-2.patch, failed testing.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

This indeed seems like the best option; hopefully browser support of picture elements picks up soon.

Committed and pushed to 8.x. Thanks!

  • Commit 9d2e9ff on 8.x by webchick:
    Issue #2227435 by mariancalinro, mdrummond: Remove noscript from picture...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.