DEV Community

Cover image for Device Memory API
Raymond Wangsa Putra
Raymond Wangsa Putra

Posted on

Device Memory API

What is this?

This is one of Web APIs that can be used to get how much memory this device got

Compatibility?

Per this article is written, it only support Chrome, Edge, and Opera

How to use it?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Device Memory API Example</title>
</head>
<body>
    <h1>Device Memory API Example</h1>
    <p id="memory-info"></p>

    <script>
        if ('deviceMemory' in navigator) {
            const memory = navigator.deviceMemory;
            document.getElementById('memory-info').textContent = `This device has approximately ${memory} GB of RAM.`;
        } else {
            document.getElementById('memory-info').textContent = 'Device Memory API is not supported on this browser.';
        }
    </script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

My observation?

One unique thing I observe it shows I only have 8GBs of RAM while running it on a 16GBs device

Top comments (0)