Exercise 2: What Actually Happens on a Successful Scan — Possible Solution ==================================================================== WHAT HAPPENS TECHNICALLY IN THIS CHAPTER'S scan.js ------------------------------ Once a barcode is detected, the script stops the camera stream and sets window.location.href to a new URL - this triggers a full browser navigation: a new HTTP request to the server, a full page reload, and an entirely fresh render of whatever template that new URL maps to. Any JavaScript state from the scan page is discarded once that navigation happens. HOW THIS DIFFERS FROM THE REACT-BASED SIBLING COURSES ------------------------------ In the React-based sibling courses, detecting a barcode calls a callback that updates in-memory component state directly - there is no page navigation, no new HTTP request for a full page, and no discarding of existing application state. The result (the looked-up product details) simply appears in the already-loaded page through a state update. WHAT CHAPTER 11'S DRF WORK WOULD CHANGE ------------------------------ Per this chapter, Chapter 11 introduces Django REST Framework specifically to expose JSON endpoints for the interactive features. If the scan flow called a JSON endpoint via fetch() instead of navigating to a new URL, the barcode lookup result could be handled in JavaScript directly, without triggering a full page reload - much closer to the React-based courses' own behavior, at the cost of writing more client-side JavaScript to manage that state by hand instead of relying on a full page render. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly describes the full page navigation triggered by window.location.href, correctly contrasts it with the React-based courses' in-memory state update with no navigation, and correctly identifies Chapter 11's DRF-based JSON endpoint approach as what could eliminate the full-page-reload behavior.