is there anyway to stop a javascript file from being loaded when on a device (mobile)? I've made a responsive design and there are a few scripts that do not get used for the mobile version so it would be good if they do not have to load.
Many thanks
Check if the browser is not
ismobile
anddocument.write
out the script:you can tell with some jquery
i have used this code before, know i got it no stack overflow but cannot remember where, if anyone one knows please add credit...
screen.width will give you the width of the users device in pixels. However, as screens become higher resolution (Samsung Galaxy Nexus has a 720p screen), this will rapidly become obsolete.
Another option includes searching the user agent string:
Unfortunately, that doesn't hit all mobile browsers according to detectmobilebrowser.com, the list actually looks more like this and you'll have to actively support this regex for the rest of your life:
The real question you have to ask yourself is "what makes a mobile browser?"
Is it screen resolution?
A certain make/model?
A certain feature set?
The line is becoming more and more blured every day, and as mobile devices become more capable, you almost have to wonder if multiple feature sets for multiple devices is a sustainable solution.