Code Monkey home page Code Monkey logo

low-web-extension's Introduction

low—web extension (v0.0.13)

Reduce energy consumption and carbon footprint of your internet browsing.

Why ? 💚🌿🌳🌲🌍

The Internet consumes about 8% of the electricity produced worldwide and emits 3 to 4% of total greenhouse gas emissions. Every request, every resource, every calculation, is small amounts of electricity consumed ... and we visit billions of pages, make billions of computer operations, load billions of terabytes... needing to run millions of servers, millions of antennas, millions of miles of fiber and especially devices like telephones always more powerful and ever more obsolete.

This extension aims to reduce our data and limit the energy consumption of our Internet browsing.

This extension affects electricity consumption when browsing the Internet but not during manufacturing. Manufacturing is the most energy consuming and polluting stage. So let's keep our phones and computers as long as possible !

How ?

A browser extension allows you to block resources and modify the content of a page. So we can optimize some content, block what is not necessary and thus limit the number of requests, weight and computer operations.

First, you need a good blocker for ad/malware/tracker like uBlock Origin, Ghostery... or a browser like Firefox or Brave. Reducing advertising and tracking is surely what will save you the most data. We made the choice in the extension not to deal with advertising, many extensions do it very well.

Video

More than 80% of the data transferred over the Internet are videos. This extension tries to limit their use and the quality of the videos:

  • when possible, the extension chooses a low video quality. For example on Youtube.com, the video will be played in 240p, 360p or 480p (Youtube, Vimeo, Dailymotion)
  • embed video iframes are blocked and a light preview is displayed. The click on a preview opens the video on the original site or in the iframe. We use oEmbed to get informations about the videos (Youtube, Vimeo, Dailymotion, Facebook).
  • optionnaly, some optimisations are done to limit dark patterns on Youtube to reduce its attraction and avoid to lose hours on Youtube. Links and image preview on homepage and video page can be hided.
  • remove autoplay and loop parameters for embed videos and native html <video>
  • optionnaly block all requests of type: video (default:false)

Image

Several optimizations are made on the images, some are blocked and some displayed in smaller sizes.

  • stop animated GIF and play them when hovering. An animated GIF force browser to re-render part of the screen, it consumes CPU/GPU processes.
  • custom embeds for Giphy images. Original animated images are blocked and replaced by static images. Animated image is loaded and played when hovering.
  • block avatar images of many services including Gravatar, Discus, Twitter, Linkedin, Github, Pinterest, Reddit and more...
  • remove biggest or hidpi images from srcset. This prevents the browser from loading images that are too big. (only works with lazy-loaded images eg. data-srcset, data-lazysrcset. None lazyloaded images are loading already when the extension starts and it is not possible to stop loading them)
  • add lazyloading to all images (native loading="lazy" or fallback) (not working due to browser restrictions, images are loading when extension start and it's not possible to stop them)
  • optionnaly block all requests of type: image (default:false)

And more

  • block different social embeds like Facebook like or share buttons. It mostly blocks scripts from embeds, so when possible embeds are still displayed and customized with injected css and when necessary datas are loaded from oEmbed.
  • add the header Save-data: on to all requests (currently based on Save-data: on). This header can be interpreted by websites to reduce weight of pages.
  • optionnaly block all requests of type: font (+ urls from font services like Google Fonts) (default:false)
  • disable css transition and animation (default:false) (:warning: break transitionend / animationend events :warning:)
  • disable <marquee> animations :P

More details

Results

Some results of optimisations from various test pages :

with extension without extension
video 456Kb / 22 requests 4Mb / 107 requests ~89%
image 993Mb / 30 requests 7.7Mb / 35 requests ~87%
social 898Kb / 78 requests 9.3Mb / 330 requests ~90%
giphy 213Kb / 31 requests 12.3Mb / 34 requests ~98%

note 1: these pages are particularly favorable for optimizations note 2: theses results are for firstload note 3: extension adds requests to local files, it increased the number of requests especially for image

Details

Some detailed explanations about functionalities of low—web extension.

Low quality video

Youtube

The video quality of Youtube can only be changed automatically on the official website not in embed. A script is injected by the extension on youtube.com to adjust the quality according to the Video Quality parameter available in options repectively 240p, 360p, 480p for Very Low, Low, Medium. (Youtube-small.js, Youtube-medium.js, Youtube-large.js)

Vimeo

The extension changes the quality of Vimeo videos when they are embedded. A 'quality' parameter can be added to the url of a vimeo iframe (eg: https://player.vimeo.com/video/156045670?quality=360p). This parameter is defined at 240p, 360p, 540p depending on the "Video Quality" option, respectively for Very Low, Low, Medium. We are looking for a solution to automatically change the quality on vimeo.com.

Dailymotion

Disabled for the moment.

Facebook

We didn't find a way to reduce automatically quality for Facebook videos. But you can set quality to standard and disable autplay in Facebook settings page : https://www.facebook.com/settings?tab=videos

Click to load a video

Embed videos iframe from Youtube, Vimeo, Dailymotion and Facebook are blocked and replaced by the preview image of the video, its title and a Play button imitating the official players. A click on these preview plays the video either on the official website, or in the iframe depending on the "Video Quality" parameter. Sometimes it is necessary to double click to launch the video.

Ex for original Youtube iframe:

  • no cache ~ 550 / 600KB / 16 requests / load ~ 800ms
  • cache ~ 20Ko / 16 requests / load ~ 650ms

Youtube iframe optimized:

  • no cache ~ 20KB / 5 requests / load ~ 220ms
  • cache ~ 7KB / 5 requests / load ~ 200ms

Technically, original iframe is blocked by extension, then an script is injected for customising blocked iframe. It loads oEmbed datas to get image and title of the video, then a new simple html (with image, title, button) is created and injected (data:text/html) into the new iframe.

You can test this functionality on this page: embed-video.html with option "Click to load a video" activated.

More technical info soon...

Video and audio native attributes

The native html5 elements <video> and <audio> are modified to consume less data. These media are paused and the following attributes are changed:

  • autoplay = false
  • loop = false
  • preload = none Websites may still force autoplay of the videos.

You can test this functionality on this page: media.html with option "Custom attributes for html element <video> and <audio>" activated.

Stop GIF animation, hover over it to play

The animation of a GIF requires the browser to permanently refresh the rendering of the GIF area (when visible in the screen), this requires a lot of CPU / GPU resources. Open a page with an animated GIF and Activity Monitor on Mac or Resource Monitor on Window, you will notice that the use of the CPU or GPU is more important. It is still possible to see the animation of the GIF by hovering over it. A Play button (white triangle with black border) indicates that the image can be animated. The extension does not yet detect if the GIF image is animated, it can sometimes indicate that the image is animated when it is a static GIF.

You can test this functionality on this page: gif.html with option "Hover over a GIF to play it" activated.

More technical informations soon.

Load Giphy GIF on hover

Giphy offers an API to access different image formats. Giphy's animated GIFs are replaced by much lighter static images. When hovering over this image, the animated GIF is loaded in medium resolution (see GiphyPlayer.js). The content of Giphy iframes (containing a GIF and many scripts) is replaced by a simple static image. The animation is loaded on hover.

You can test this functionality on this page: giphy.html with option "Hover over a GIF to play it" activated.

Specific website optimisations

The best way to reduce your data is not to use the Internet or to reduce your use of it. But it's not always easy... Most sites use techniques called "dark-patterns" to keep us on their site so that we consume more content. But in the case of sites like Youtube, these are petabytes of data that we consume more and a lot of lost time... This feature is only available for Youtube at the moment. It is possible to reduce the data and / or the display.

Youtube:

  • display of preview images in low resolution (mqdefault.jpg)
  • blocking of animated images when hovering over a preview
  • blocking of video autoplay on a Channel page
  • blocking of previews and suggestions on the home page and on a video page

You can test this functionality on youtube.com with option "Specific optimisation for most used websites" activated.

We strongly recommend the Minimal extension which limits these dark-patterns. Note: if you use the low—web and minimal extensions, deactivate the option: "Specific optimization for most used websites" of the low—web extension

Smallest image (srcset)

An image in html can be defined in different sizes via the parameters srcset and sizes. The browser will load the image most suitable for your screen. In general, he will choose a larger image. The extension removes urls from larger images. The browser will therefore load the smallest of the images.

You can test this functionality on this page: srcset.html with option "Image quality" activated.

Note: this technique only works for "lazy-loaded" images (generally data-srcset).

Header 'Save-data: on'

When requesting a file on the Internet some info is sent: headers. There is a header that says you want to save data: "Save-data: on". The site you are visiting can then adapt the content to reduce the data, by not loading, for example, images or a video. For the moment, few sites take this header into account. The extension adds this header for each request.

Block fonts

An option is available to block fonts. Font files are not very heavy but now most sites have 3, 4, 10 font files. Browsers will used system fallback fonts. Sorry my dear AD friends. Font files may be used for icons, like fontawesome. We choose to white-list some icons font to avoid broken icons and design.

You can test this functionality on this page: fonts.html with option "Block Fonts" activated.

Feel free to PR or send me an email (vico @@@ lowweb.tech) to add more online font services into fonts.txt

Block social media embed

Social media contents are often shared, mostly in the form of iframe. These iframes contain a lot of unnecessary content and scripts. It is sometimes possible to block these files and display only the media (image, text ...). The extension can add a style to simulate the style of the original content (ex: tweet, reddit...) Other social media content such as a Like, Share, Follow button, etc. is useless and blocked. They are mainly there to track us (most often via Facebook).

You can test this functionality on this page: social.html with option "Block social media embeds" activated.

Feel free to PR or send me an email (vico @@@ lowweb.tech) to add more embeds urls into social.txt

Block avatar images

An option is available to block avatar images. Avatar images are generally light but often very numerous. The urls of blocked images are in this avatar.txt list, the syntax is the same as Ad Block Plus Filters.

You can test this functionality on this page: avatar.html with option "Block avatar images" activated.

Feel free to PR or send me an email (vico @@@ lowweb.tech) to add more avatar urls into avatar.txt

Optimised CSS

Some CSS properties can affect rendering performance of a page (and therefore increases its energy consumption). Injected CSS can : - disable animation and transition (option: Disable CSS animation) - optimize font rendering (option: Optimize font rendering) - optimize image rendering (through content-visibility:auto)

Development / Build

  • tested on node 12.20 / npm 6.14
  • installation : npm install
  • development : npm start (firefox) or npm run dev:chrome or npm run dev:opera
  • build : npm run build (firefox, chrome, opera) built to dist/ folder or npm run build:firefox or npm run build:chrome

Pages for tests : https://lowwebtech.github.io/low-web-extension/

Contribute

Licence

Code released under the GNU GPLv3 License.

low-web-extension's People

Contributors

dependabot[bot] avatar lowwebtech avatar vicocotea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

low-web-extension's Issues

Whitelist viewing of direct media

Direct media files (.mp4, .gif etc) should get whitelisted automatically. Now if I want to open a direct link to a gif image, it gets changed to first-frame png by the extension yet the url stays the same (ending in .gif). This breaks other add-ons and seems unnecessary.

The extension should have a way to exclude direct media links from processing.

WebRequest type to block ?

I know there will be soon the new api Declarative Net Request, but for now with the WebRequest API, I don't what to do with these types :

  • beacon
  • csp_report
  • ping
  • speculative
  • web_manifest
  • websocket
  • xbl
  • xml_dtd
  • xslt

Should I block them ?
Can you explain what are they used for ?

Thanks

Add data-sveltekit-preload-data="tap" to HTML body for SvelteKit applications

In Sveltekit, the preload function is used to load data on the server side before the page is rendered. This can help improve the performance and user experience of the application by reducing the amount of time it takes for data to be displayed on the screen. However, it also results in unused data and excessive electricity consumption.

When you use the data-sveltekit-preload-data="tap" attribute on the HTML body, it tells Sveltekit to only load the data for that link when it is tapped or clicked by the user. This is in contrast to using data-sveltekit-preload-data="hover", which would load the data when the user starts to hover over it. The hover value will result in false positives for navigation and extra data being loaded.

Because Sveltekit is growing in usage, we should edit the HTML body attribute to data-sveltekit-preload-data="tap". I am not sure how we would go about implementing this because there is no contribution guide.

Sveltekit preloading documentation: https://kit.svelte.dev/docs/link-options
Potential code: document.documentElement.setAttribute("data-sveltekit-preload-data", "tap")

If you have any questions, please let me know. If I do not hear back soon, I will try to search through the existing codebase and find where adding this is appropriate.

Dark mode and accessibility

Hi, thanks for creating this extension 💚

I would like to create a dark mode for the extension ( to reduce energy on end-user devices ), and to make some accessibility tweaks.

Videos not always blocked, gifs not blocked, images not blocked?

Hello, thank you for your extension. But I just installed it and it didn't seem to work well.
I use Firefox, under Lubuntu 22.04.


VIDEOS.

I made a test on Youtube.
First it seemed to work, then just visiting a Youtuber's page, I heard the voice of a video!
Simply being first in its homepage, I went to the About page, then came back in the homepage, and it is here that the video had begun to play. So at first page opening it was OK, but at second opening the blocking didn't work anymore.
An extension like Image Video Block doesn't have this problem, so as its code is open source, maybe you could check it for fixing yours, but I'm not a developper, I don't know, I said it just in case it helps.

A possible explanation I imagined (?).
When Click to load a video and even Block Medias are on (o)True, then one could expect is will stay blocked, but no because Custom attributes for html element can invalidate/disable it maybe.

So problem comes maybe from features (not-)conditionalities being a bit contradictory or conflicting or redundant?
Maybe Click to load a video could be displayed as an option of Block Medias, and could be disabled (in grey) if Block Medias is (o)False. If a media is not blocked, it loads (and maybe plays). If it is blocked, it has the optional possibility with a click to load and play. It would be either one or the other, if one allows second, it's allowed, but if it doesn't, it is not allowed. So prevent the Click to load a video when it is blocked could prevent the playing that I saw?
Maybe also the conflict (if exists) is with Custom attributes for html element instead of Click to load a video (or both).
Or something else, I'm a bit lost.


GIF.

GIF play and loop without hovering here https://www.localcdn.org/tutorial and maybe everywhere.


IMAGES.

I also noticed many (all?) images were still here, though Block Images was on (o)True.
Is it worth indicating a page? As it seems to be like this almost everywhere.
A bit like videos, maybe Image quality disables Block Images
But as I don't know much coding, maybe it is because not all images are between tags.


Maybe oyher features don't work either, or also it's me who don't understand how this extension works.

Extension Options in frame

Hello,

When I get into the options, I have to scroll to the right to check the buttons / radio buttons, they don't display on the full page : so I can't have the title of each option + the check mark on screen at the same time. ( + the options take only half of my screen, all the space on the right side is empty, maybe that's a FF parameter ? )

Thank you.
Firefox 74.0 (64 bits) + Windows 10

Peter; France
Clipboard01

Video quality is not updated on firefox

🐛 Bug Report

Explicit title

  • Is this a regression? : don't know

🔍 Reproduction Steps

  • Go to a youtube video page with the plugin enable
  • Set preset on low or medium quality
  • Right click on the video on "stats for nerds" and current resolution

Expected behavior

Current resolution should be reset according to the plugin setting

Tested environment (optional)

Firefox 78.3 on Linux

Disable Push from server might help reducing data downloads

Regarding this documentation
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Save-Data

Disabling HTTP/2 Server Push (RFC 7540, section 8.2: Server Push) might be desirable too for reducing data downloads.

The side effect would be that background update from some website may not work, the user might need to refresh the content.

I wonder the data saving on website such as facebook or gmail.
It can be measure first before adding this option.
In Firefox the relevant option is dom.push.enabled

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.