I want to serve the same DOM to all browsers and devices, e.g. desktop, tablet, phone, etc. However, I do not want the assets (images, stylesheets, etc.) intended only for desktop to be downloaded on mobile and waste HTTP requests and bandwidth.
Is there any way to manipulate the DOM before the browser starts downloading the assets, using strictly client-side Javacript, depending on the device and browser?
I feel like using the DOMContentLoaded event (https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) gets me close..
EDIT: I have found that mobify.js seemingly does what I am after: https://www.mobify.com/mobifyjs/v2/docs/
They provide a 'Capturing API for manipulating the DOM before any resources have loaded'. It also appears to be done with client-side Javascript. Will have to look through their source on GitHub to see how they are doing it.