ai / ai/webp-in-css

Not compatible with SSR

Aperta
#17 10 commenti 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
343
Fork
26
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Well, this library is not SSR compatible, and there are only two reasons why not:
- `README` tells to add it to the `head` or `bundle`, while it has to be inlined just after `body` tag
- it uses `onLoad/onError` handlers which are __async__

## Let's make it work right!
Long story short - here is working sandbox - https://codesandbox.io/s/crazy-ganguly-hmhe8

- it __inlines__ `base64 img` before the body to tell the browser about it. The `img` is __invisible__.
- it "checks" `img` synchronously after creating, and it does work! (only with a real `img` tag, preload does not help).
- so it sets class to the body __here and now__, and the following HTML would use `webp`
- as long as dataURI inlined in the same document - it does not affect gzip size.

## Tested
In `Chrome`(webp ✅), `FireFox`(webp ✅), and `Safari`(no webp, as expected)

## Outcome

This library becomes SSR friendly!

Happy to open PR with a more compact version of the sandboxed example, however, the main changes are expected at the README level

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.