Device resolution detection module
JavaScript HTML
Latest commit 111028c Sep 12, 2016 @ryanve committed on GitHub Merge pull request #3 from ryanve/next
0.4.0 release
Permalink
Failed to load latest commit information.
.editorconfig add .editorconfig Sep 11, 2016
.gitattributes Rework build setup Mar 31, 2014
.gitignore 0.1.0 Sep 18, 2013
LICENSE add LICENSE file Sep 12, 2016
README.md readme tweaks Sep 11, 2016
package.json 0.4.0 bump Sep 12, 2016
res.js refactor Sep 11, 2016
test.html group tests in console where possible Sep 11, 2016
test.js line up values Sep 11, 2016

README.md

res

CSS resolution detection in JavaScript

npm install res --save

API

res.dpi()

  • Get resolution in dpi
  • @return number

res.dpcm()

  • Get resolution in dpcm
  • @return number

res.dppx()

  • Get resolution in dppx
  • @return number

Usage

var res = require('res')
res.dppx() // 1
res.dpi() // 96
res.dpcm() // 37.79527559055118

Technical notes

Use with care

res was mainly written for investigative purposes. Making retina design accommodations can be impractical. Consider alternatives to resolution detection.

Example outputs

Device res.ddpx() res.dpi() res.dpcm()
desktop at default zoom 1 96 37.79527559055118
iPhone 4s at default zoom 2 192 75.59055118110236

Compatibility

Browsers with resolution detectable by res

  • Webkit (Chrome/Safari/Android)
  • Firefox 18+
  • Opera 11.1+ (Presto 2.8+)
  • IE 6+

Methods return 0 where undetectable.

Related resources

License

MIT