AnalyserMethodologyBarometerWidget and API

Widget, badge and API

Show your site’s rating or use CarbWeb’s measurements in your own tools. It is free, with no sign-up.

The widget

A discreet badge in the bottom right corner of your site shows the rating and the grams of CO₂ per visit. Clicking it opens the details (weight, Swiss electricity, hosting) and the link to the report. It is the one you can see at the bottom of this page, for carbweb.ch.

<script src="https://carbweb.ch/widget.js" data-page="exemple.ch" data-lang="en" defer></script>
  • First analyse your page on the homepage: without a report, the widget does not appear.
  • data-page: the page measured (by default, the site’s domain).
  • data-position="bottom-left": on the left instead of the right.
  • data-theme: auto (default), light or dark.
  • data-lang: fr, de or en (by default, your page’s language).
  • data-target="#carbweb": show the pill inside an element of your page (for example the footer) instead of a corner of the screen. Just add <div id="carbweb"></div> where you want it.
  • For a bare domain (data-page="exemple.ch"), the widget and badge show the site average if a whole-site analysis has been run, otherwise the homepage measurement.
  • The widget is isolated in a Shadow DOM: it does not change your site’s styles and weighs about 9 KB.

The badge

First analyse your page on the homepage: the report shows the code ready to copy. The badge shows the latest mobile measurement and updates with every new analysis.

<a href="https://carbweb.ch/rapport/exemple.ch"> <img src="https://carbweb.ch/badge/exemple.ch.svg?lang=en" alt="CarbWeb – exemple.ch" height="24"> </a>

For a specific page: /badge/exemple.ch/blog.svg. A page that has never been measured shows “not measured”. Add ?lang=de or ?lang=en for the language.

Run an analysis

POST https://carbweb.ch/api/analyze Content-Type: application/json { "url": "https://exemple.ch", "strategy": "mobile" }
  • strategy: mobile (default) or desktop.
  • Response: { slug, result, cached }. An analysis takes 15 to 40 seconds.
  • A page measured less than 6 hours ago returns the stored result.
  • Limit: 10 new analyses per IP address every 10 minutes (429 response beyond that).
  • Each result is published at /rapport/<slug>.

Analyse a whole site

POST https://carbweb.ch/api/site Content-Type: application/json { "url": "exemple.ch" } GET https://carbweb.ch/api/site?url=exemple.ch
  • The POST starts the analysis in the background (202 response): up to 15 pages, in a few minutes.
  • The GET returns the progress (status: "running", list of pages), then the summary (summary: average, median, rating, shared fixes).
  • The same site is re-analysed at most once a day. Limit: 3 site analyses per IP address per hour.
  • The report is published at /rapport/site/exemple.ch.

Read a report

GET https://carbweb.ch/api/rapport?url=exemple.ch

Returns the latest mobile and desktop measurements, and the analysis history. The barometer data is at /api/barometre. These endpoints accept requests from any site (CORS).

Main fields

co2PerVisit
grams of CO₂ per visit, SWD v4 model, global average
co2PerVisitSwiss
same calculation with Swiss electricity
grade
Sustainable Web Design rating, from A+ to F
totalBytes
bytes transferred on a first visit
opportunities
suggested fixes, with the files and bytes that can be saved
potential
estimated weight, CO₂ and rating after fixes
isGreenHosted
host recognised by the Green Web Foundation

The calculation is explained in detail in the methodology.

CarbWeb’s code is released under the MIT licence.