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?

Top comments (3)

Collapse
 
ivan_jrmc 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

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