Skip to content

Instantly share code, notes, and snippets.

@estahn
Created December 2, 2013 01:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save estahn/7743435 to your computer and use it in GitHub Desktop.
Save estahn/7743435 to your computer and use it in GitHub Desktop.
/**
* WebP support check
*
* The cookie will be set for the top level domain, e.g. ".zanui.com.au".
* This will enable access from "static.zanui.com.au".
*
* Script might not work for local environments.
*
* @author <a href="mailto:enrico.stahn@rocket-internet.de">Enrico Stahn</a>
*/
;(function ($, window, undefined) {
'use strict';
if ($.cookie('__webp') !== undefined) {
return;
}
var domain = window.document.location.hostname.replace(/www\./, '');
var cookieOptions = { expires: 365, path: '/', domain: '.' + domain };
var image = new window.Image();
image.onload = function () {
if (!!(image.height > 0 && image.width > 0)) {
$.cookie('__webp', 1, cookieOptions);
}
};
image.onerror = function () {
$.cookie('__webp', 0, cookieOptions);
};
image.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
})(jQuery, window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment