Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine duplicate media queries #1

Open
westonruter opened this issue Sep 1, 2021 · 0 comments
Open

Combine duplicate media queries #1

westonruter opened this issue Sep 1, 2021 · 0 comments

Comments

@westonruter
Copy link
Collaborator

Given this example input:

<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Native &lt;img&gt; lazy-loading is coming to the web! <a href="https://t.co/LgF7F1iMgR">https://t.co/LgF7F1iMgR</a> &lt;img loading=lazy&gt; defers offscreen images until the user scrolls near them. Shipping in Chrome ~75 <a href="https://t.co/4gR7lvx4zx">https://t.co/4gR7lvx4zx</a> <a href="https://t.co/luCHEfLkKD">pic.twitter.com/luCHEfLkKD</a></p>— Addy Osmani (@addyosmani) <a href="https://twitter.com/addyosmani/status/1114777583302799360?ref_src=twsrc%5Etfw">April 7, 2019</a></blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

The output is:

<div id="layout-shift-termination-0-24900068026844013">
<style class='layout-shift-termination'>
#layout-shift-termination-0-24900068026844013 { contain: style layout inline-size; }
#layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:606px; }
@media only screen and ( max-width: 1536px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:606px; } }
@media only screen and ( max-width: 1366px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:606px; } }
@media only screen and ( max-width: 768px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:606px; } }
@media only screen and ( max-width: 700px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:606px; } }
@media only screen and ( max-width: 600px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:606px; } }
@media only screen and ( max-width: 500px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:568px; } }
@media only screen and ( max-width: 414px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:543px; } }
@media only screen and ( max-width: 375px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:466px; } }
@media only screen and ( max-width: 360px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:457px; } }
@container ( max-width: 1536px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:606px; } }
@container ( max-width: 1366px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:606px; } }
@container ( max-width: 768px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:606px; } }
@container ( max-width: 700px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:606px; } }
@container ( max-width: 600px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:606px; } }
@container ( max-width: 500px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:568px; } }
@container ( max-width: 414px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:543px; } }
@container ( max-width: 375px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:466px; } }
@container ( max-width: 360px ) { #layout-shift-termination-0-24900068026844013 > .layout-shift-terminated { min-height:457px; } }
</style>
<script class='layout-shift-termination' async>(function (root) {
    setTimeout(function () {
      [].map.call(root.querySelectorAll(".layout-shift-termination"), (el) =>
        el.remove()
      );
    }, 4000);
  })(document.getElementById("layout-shift-termination-0-24900068026844013"))</script>
<div class="layout-shift-terminated">
              <blockquote class="twitter-tweet"><p lang="en" dir="ltr">Native &lt;img&gt; lazy-loading is coming to the web! <a href="https://t.co/LgF7F1iMgR">https://t.co/LgF7F1iMgR</a> &lt;img loading=lazy&gt; defers offscreen images until the user scrolls near them. Shipping in Chrome ~75 <a href="https://t.co/4gR7lvx4zx">https://t.co/4gR7lvx4zx</a> <a href="https://t.co/luCHEfLkKD">pic.twitter.com/luCHEfLkKD</a></p>— Addy Osmani (@addyosmani) <a href="https://twitter.com/addyosmani/status/1114777583302799360?ref_src=twsrc%5Etfw">April 7, 2019</a></blockquote>
              <script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
            </div>
</div>

Note how the first 5 media queries all have the same min-height:606px; These can either be eliminated entirely because the initial min-height is 606px, or else they can be merged into one media query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant