Urgent.News

What's breaking now, across thousands of outlets.

Tech

Prerendering a page per device, and the cache key that has to agree

A marketing page with no per visitor content should be built once and handed out as a file, which is what prerendering means here: the build writes the HTML, and the server answers with it instead of rendering again. The page I had to do this to was not quite static. Its footer is an accordion on a phone and a grid on a laptop, and a few sections below it differ the same way. Two rendered…

Prerendering a page requires creating a separate HTML file for each device type that will interact with it. This process involves generating two distinct versions of the same document, one optimized for desktop devices and another tailored for mobile devices. The reason for this duplication is to ensure that the browser can make the appropriate choice about which version to display at the time the page is requested.

CSS media queries play a crucial role in this process by rendering both versions of the page and hiding one based on the device's capabilities. This ensures that the same content is present in the document, but the browser selects the version best suited for the user's device before it is loaded.

JavaScript further refines this decision-making process by determining the optimal rendering after the page has fully loaded. However, this approach leaves a gap as the first paint, or the initial rendering of the page, is an educated guess and can result in an undesired user experience.

To avoid this, building the page with the correct version from the beginning (at build time) is a more efficient strategy. This results in one version of the page per device type, stored in a separate file. This approach ensures that the HTML read by web crawlers is consistent across all devices, eliminating confusion about the content that each specific device will see.

Next.js, a popular React framework, facilitates this process within its App Router in version 15. By opting in with a specific export, a page can be designated to use this prerendering technique. However, this page must not attempt to render itself as it would without the device-based rendering. Instead, it should direct traffic to the appropriate device-specific file through a rewrite mechanism that occurs before the request reaches the route.

By implementing these strategies, the application can effectively serve the correct content to each device type while minimizing guesswork and ensuring a consistent user experience.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Extend vs regenerate vs section edit: picking the right move for short soundtrack beds

When a demo video’s bed is close but not shippable, I used to regenerate from zero. That “fixed” length sometimes and broke everything else.

  • Extend used when full length acceptable and region conflicts with voice-over
  • Regenerate chosen when extending causes issues or direction is wrong
  • Section edit preferred for specific bar fixes without full regenerate

Beyond Features: Building Workflow-Driven Software with EduRoom and ERP

In software development, it is easy to focus on features, dashboards, and integrations. But building useful software starts with understanding the workflow behind the problem.

  • ERP software focuses on inventory insight, not just stock levels.
  • Effective software integrates actions into coherent workflows, not just features.

More from Thursday 29 October →