Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Allows you to get the device pixel ratio using JavaScript.

## Size and delivery

Currently, `getDevicePixelRatio.js` compresses to around 318 bytes (~0.3 KB), after minify and gzip. To minify, you might try these online tools: [Microsoft Ajax Minifier]:(http://ajaxmin.codeplex.com/), [Uglify]:(http://marijnhaverbeke.nl/uglifyjs), [Yahoo Compressor]:(http://refresh-sf.com/yui/), or [Closure Compiler](http://closure-compiler.appspot.com/home). Serve with gzip compression.
Currently, `getDevicePixelRatio.js` compresses to around 221 bytes (~0.2 KB), after minify and gzip. To minify, you might try these online tools: [Microsoft Ajax Minifier](http://ajaxmin.codeplex.com/), [Uglify](http://marijnhaverbeke.nl/uglifyjs), [Yahoo Compressor](http://refresh-sf.com/yui/), or [Closure Compiler](http://closure-compiler.appspot.com/home). Serve with gzip compression.

## Sample

Expand Down
2 changes: 1 addition & 1 deletion getDevicePixelRatio-min.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/*! GetDevicePixelRatio | Author: Tyson Matanich, 2012 | License: MIT */
(function(n){n.getDevicePixelRatio=function(){var t=1;return n.screen.systemXDPI!==undefined&&n.screen.logicalXDPI!==undefined&&n.screen.systemXDPI>n.screen.logicalXDPI?t=n.screen.systemXDPI/n.screen.logicalXDPI:n.devicePixelRatio!==undefined&&(t=n.devicePixelRatio),t}})(this);
(function(b){b.getDevicePixelRatio=function(){var a=b.screen||{},c=a.systemXDPI||1,a=a.logicalXDPI||1;return c>a?c/a:b.devicePixelRatio||1}})(this);
19 changes: 9 additions & 10 deletions getDevicePixelRatio.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/*! GetDevicePixelRatio | Author: Tyson Matanich, 2012 | License: MIT */
(function (window) {
// device pixel ratio even before dom ready
// http://stackoverflow.com/a/29913175
window.getDevicePixelRatio = function () {
var ratio = 1;
// To account for zoom, change to use deviceXDPI instead of systemXDPI
if (window.screen.systemXDPI !== undefined && window.screen.logicalXDPI !== undefined && window.screen.systemXDPI > window.screen.logicalXDPI) {
// Only allow for values > 1
ratio = window.screen.systemXDPI / window.screen.logicalXDPI;
}
else if (window.devicePixelRatio !== undefined) {
ratio = window.devicePixelRatio;
}
return ratio;
var screen = window.screen || {};
var systemXDPI = screen.systemXDPI || 1;
var logicalXDPI = screen.logicalXDPI || 1;
// To account for zoom, change to deviceXDPI instead of systemXDPI
if (systemXDPI > logicalXDPI) return systemXDPI / logicalXDPI;
// Fall back to legacy devicePixelRatio or return 1
else return window.devicePixelRatio || 1;
};
})(this);