Frontory

Open code, practice, and notes →

Download source with English comments · for reading

Canvas 2D · 21 High Resolution and Responsive Layout

Series contents · Technology map

Stage: Scene Editing and Compositing · Editable example · Storage ID: canvas-2d-step-21

Goals and learning outcomes

Prerequisites

Prerequisite concepts: Prerendering, Invalidation. Prepare the result files and observation records from Unit 20.

Key concepts and explanations

Observation Target

ResizeObserver detects element size changes. Even when window dimensions stay the same, a change in panel width requires adjusting the canvas buffer.

Resolution Budget

Increasing DPR increases pixel count by area. Compare quality and cost to choose a cap, and record that choice.

Practice setup

First check the execution scope guidance on the example screen. The following describes preparation for extending the assignment in a separate project. Implement this yourself in an HTML and ES module project on a separate local HTTP development server. Record the browser version, viewport, and DPR.

The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.

Practice tasks

  1. Prepare day-21.js and index.html in the external practice project. Observe the container with ResizeObserver and recalculate CSS dimensions and buffer dimensions.
  2. Add a DPR cap select and redraw while preserving existing shape coordinates.
  3. In an environment where actual devicePixelRatio is at least 2, compare DPR caps of 1 and 2. Expected: with the same CSS dimensions, the number of buffer pixels becomes four times larger. Record sharpness and frame measurements in day-21-notes.md, and record environments with actual DPR of 1 as a separate condition.

Variables to observe

VariableBaselineChangeExpected change / hypothesis
DPR CapIn an environment where actual devicePixelRatio is at least 2, DPR cap 12Lines may become sharper, but the number of processed pixels becomes four times larger

Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.

Completion criteria

Self-check

  1. When might devicePixelRatio change during execution?
  2. Why does state disappear if you only resize the buffer?

Official references

Linked example and execution scope

Example source · Runtime environments and limits

This is an editable browser experiment. Measurements vary with the current device and browser.

Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.

Next learning

Previous: Static Layers and Caching · Next: Accessible Canvas Controls

Open code, practice, and notes →