Created
December 2, 2013 01:20
-
-
Save estahn/7743435 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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:[email protected]">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