What to do if you don't want to load JS files on mobile devices? Let's say, the navigation of a website uses javascript (dropdown for example), and that Javascript is loaded within the .info file

Example of the .info file of an Omega Subtheme

scripts[0] = 'js/navigation.js'
scripts[1] = 'js/hoverintent.js'
scripts[2] = 'js/jquery.fancybox.pack.js'

Let's say, I don't want to load scripts[0] on mobile. What would be the easiest solution for this?

1 Answer 1


The easiest (probably only realistic) way would be to create a second, javascript-less theme, and use the ThemeKey module to show that theme to mobile users based on user agent string. It's not exactly a foolproof method but then device-sniffing never is.

The other option would be to write some javascript which responds to the Omega media query change event, and hooks/unhooks all other javascript events on the page based on the current device size. I can imagine that being very difficult to manage though.

The proper solution would be to design the theme in a mobile-first manner, building up the javascript functionality as you go and managing how it reacts to different breakpoints at an earlier stage.

Removing all javascript for mobile devices means your users will be experiencing a site like they would have 10 years ago, with no UI richness. These days people expect more than that, especially since their devices can easily handle javascript/

  • I see a "responsive-layout-mobile" class when viewing the website on mobile, maybe I can use that classname to disable the javascript code within the JS file...? Jun 20, 2013 at 11:55
  • 1
    It would be difficult, but it is theoretically possible. You can bind to the change event with $('body').bind('responsivelayout', function(e, d) {... and check the body's class to tell what breakpoint is currently being used
    – Clive
    Jun 20, 2013 at 11:59
  • I'm using BROWSCAP to disable some blocks on MOBILE. Isn't it a good idea to use this function for this issue also? Jun 20, 2013 at 12:37
  • I'm not sure, what you're doing is far beyond 'normal practice' so I don't really know what to advise except what's already I'm the answer I'm afraid
    – Clive
    Jun 20, 2013 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.