Git Product home page Git Product logo

amp-img-vs-img's Introduction

<amp-img> vs. native <img>

Toolkit to measure difference in web vitals when <img> is server-side rendered in every <amp-img>.

If you have a large set of URLs, then simply run:

npm install
node filter.js my_list_of_urls.txt > fetch_all.sh
chmod +x fetch_all.sh
./fetch_all.sh
./benchmark.sh

Otherwise, see individual steps.

0. Install

npm install

1. Filter and resolve URLs

A text file containing URLs is filtered and outputs a shell script:

node filter.js my_list_of_urls.txt > fetch_all.sh
chmod +x fetch_all.sh # make runnable
  1. Takes a list of URLs of AMP documents, or documents that link to an AMP version
  2. Filters them randomly*
  3. Resolves AMP version if linked
  4. Prints as shell commands, to output into script (> fetch_all.sh)
# file is written like:
node fetch.js `printf "%q" "https://paired-amp/amp/url.html"`
node fetch.js `printf "%q" "https://amp-first/url.html"`
# etc.

* optional additional argument for inclusion probability:

node filter.js my_list_of_urls.txt 0.000045 > fetch_all.sh

use 1 to include all urls:

node filter.js my_list_of_urls.txt 1 > fetch_all.sh

2. Fetch & transform URLs

To transform the previously filtered URLs, execute output script:

./fetch_all.sh

Otherwise, run command for an individual URL:

node fetch.js "https://some-url-probably-amp.com/some/path"

...which inserts into output/:

output/
  some--url--probably--amp-com/
    url.txt                    # full url
    amp-img__unoptimized.html  # as-is
    amp-img.html               # optimized
    img.html                   # optimized, using native <img>

amp-img.html and img.html are transformed like a cache would by using the AMP optimizer.

3. Measure

Use tachometer to measure for LCP and CLS on documents transformed previously:

./measure.sh

This compares metrics between optimized output documents:

  • output/**/amp-img.html
  • output/**/img.html

Results are output as result-* files:

output/
  some--url--probably--amp-com/
    ...
    result-lcp.json            # LCP: full results
    result-lcp.csv             # LCP: summary table
    result-cls.json            # CLS: full results
    result-cls.csv             # CLS: summary table

LCP and CLS are measured using a PerformanceObserver, see inline-perf-script.js to see how results are measured.

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.