Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.0.2 regression #49

Open
rounce opened this issue Jul 8, 2022 · 4 comments
Open

0.0.2 regression #49

rounce opened this issue Jul 8, 2022 · 4 comments

Comments

@rounce
Copy link

rounce commented Jul 8, 2022

for example:

<img src="https://godon.ru/kyh1009.png"/>
<img src="https://forumupload.ru/uploads/0019/3c/8c/46/376640.webp" /></p>
<script src="https://unpkg.com/[email protected]/dist-cjs/polyfills.js"></script>
<script src="https://unpkg.com/[email protected]/dist-cjs/webp-hero.bundle.js"></script>
<script>
        var webpMachine = new webpHero.WebpMachine();
        webpMachine.polyfillDocument();
</script>

don't work. v0.0.1 works just fine.

@chase-moskal
Copy link
Owner

@rounce thank you for this report, i will investigate this as soon as i can

@chase-moskal
Copy link
Owner

@rounce

okay, i've done a quick investigation into this issue.

the problem:
it appears that the new improvedWebpImageDetector function was failing. this new function uses a fetch calls (meant to target the cache) to obtain the mime type of each image, to accurately assess whether the image is a webp (ignoring the file extension) -- and the problem, is that this function was failing to fetch the mime types for these cross-origin image resources.

workaround solution:
we can specify to WebpMachine to instead use the older function defaultDetectWebpImage.

<img src="https://godon.ru/kyh1009.png"/>
<img src="https://forumupload.ru/uploads/0019/3c/8c/46/376640.webp" /></p>
<script src="https://unpkg.com/[email protected]/dist-cjs/polyfills.js"></script>
<script src="https://unpkg.com/[email protected]/dist-cjs/webp-hero.bundle.js"></script>
<script>
  var webpMachine = new webpHero.WebpMachine({

    // this setting should fix the issue
    detectWebpImage: webpHero.defaultDetectWebpImage,

    // this setting is for debugging and testing,
    // to force webpHero to convert webp's,
    // even when it's not necessary
    webpSupport: Promise.resolve(false),
  });
  webpMachine.polyfillDocument();
</script>

@rounce
Copy link
Author

rounce commented Jul 9, 2022

Thanks for the quick response. The workaround works

@chase-moskal
Copy link
Owner

🍻

i should also mention that the workaround operates by checking for ".webp" extensions, which means, using the workaround, all your webp images must end in the .webp extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants