Git Product home page Git Product logo

Comments (2)

n0099 avatar n0099 commented on May 28, 2024
git clone https://github.com/Kagami/avif.js
npm i
git apply parcel.patch # this step is important
npm start

In the dist dir it will contain the demo.js, avif-sw.js, dav1d.wasm (the AV1 polyfill) and their source map files.

An example of using api exposed from avif.js can be seen here:

avif.register(navigator.serviceWorker.register("../avif-sw.js"), {

from avif.js.

n0099 avatar n0099 commented on May 28, 2024

Detailed example:

  1. Create file /index.js (filename is not important) with the following content:
import avif from './avif.js';
avif.register(navigator.serviceWorker.register('avif-sw.js'), {
    wasmURL: 'https://example.com/dav1d.wasm')
});
  1. Then run ./node_modules/.bin/parcel build index.js
  2. The /dist/index.js will be your UMD build, you can use it by a static import like <script src="url/to/dist/index.js"> or dynamically load it (like $.getScript() or append a <script src=""> tag) when you detected the user's browser does not support decoding avif natively.
    3.1. How to detect avif supporting: https://github.com/Modernizr/Modernizr/blob/6d56d814b9682843313b16060adb25a58d83a317/feature-detects/img/avif.js
    3.2. and av1 codec: https://github.com/Modernizr/Modernizr/blob/86ebb0447a8f698b22320b2bb560968050d47cf7/feature-detects/video/video.js#L60 or use a simply one-linear document.createElement('video').canPlayType('video/mp4; codecs="av01"') === ''
    3.2.1 If the user's browser (for example within the range chrome 58~70) doesn't have av1 codec then the wasm-based dav1d.js AV1 polyfill will be served from /dav1d.wasm.
    3.2.2 so the content of url https://example.com/dav1d.wasm should be same with the file /node_modules/dav1d.js/dav1d.wasm, you can just upload it.
  3. /dist/index.js will contain only the bundled content of avif.js and index.js, so you will still have to put the /dist/avif-sw.js under your domain root url or the /dist/index.js will be unable to register the service worker from 404.
  4. If you wanna stop using the avif.js for your site, you can't just delete the /dist/index.js and remove its references, but also have to unregister the avif-sw.js worker to prevent all future web requests with url ends with .avif being staled by this service worker that caused by following execution flow:
    decodeAvif(client, id, msg.data);

    return waitForClient[client.id].ready.then(() => {

    avif.js/avif.js

    Line 126 in 69b5290

    navigator.serviceWorker.controller.postMessage({type: "avif-ready", data: swOpts});

    initPolyfill(msg.data).then(() => setClientReady(e.source.id));

    waitForClient[cid].resolve();

from avif.js.

Related Issues (13)

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.