javascript - Separate js-code for desktop and mobile visitors in Rails -
i have rails app have 50 or js-functions organized in separate files, in app/assets/javascripts folder.
i'm starting remake pages mobile visitors, detecting them in controller method:
def mobile_agent? request.env["http_user_agent"] && request.env["http_user_agent"][/(iphone|ipod|blackberry|android)/] end and serving them separate views content-wise different "desktop" views.
i don't want javascript files (and it's code) used desktop visitors load mobile visitors, , vice versa.
one way skip loading js-assets alltogether
<%= javascript_include_tag "application" unless mobile_agent? %> but put mobile js-files?
or better suggestions?
you can have many manifest files want. put them in /app/assets/javascripts , compiled automatically. can have:
mobile.js:
//= require sharedjs //= require mobilejs desktop.js:
//= require sharedjs //= require desktopjs and in layout file, like:
<%= javascript_include_tag "mobile" if mobile_agent? %> <%= javascript_include_tag "desktop" unless mobile_agent? %>
Comments
Post a Comment