DEV Community

Kaztic
Kaztic

Posted on

Rendering Different JavaScript files based on screen size

So I coded two different Js files with tailwind
one for desktop and one for mobile
How can I render the desktop file and the mobile file when the screen is big and small respectively?

Discussion (3)

Collapse
ivanjeremic profile image
Ivan Jeremic

Are you using some framework like React or Svelte? If yes there are helpful hooks.

Collapse
hacker4world profile image
hacker4world

You can use window.innerWidth to check screen size then conditionally render file based on it

Collapse
eyec profile image
eye-c • Edited on

Tailwind lets you apply breakpoints:
tailwindcss.com/docs/responsive-de...