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

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay