0

I have a plugin.js that combine all my plugins for my responsive build. This plugin.js is unnecessarily bulky for mobile. I would like to create 2 plugin.js to switch between for mobile or desktop.

What is the best practice for reducing overhead for mobile scripting?

Examples: I have a complicated jQuery slider for desktop viewing but I would like that script not to load for mobile.

For this project i'll be using: HTML5, Wordpress, jQuery, Modernizr.

4

2 回答 2

1

It depends what you define as mobile. If it's all devices below a certain width, you can test for that, and then prevent the script running with an if statement.

$(function(){
    var mobile;
    if (window.width < 481) {
        mobile = 1; 
    }

    if (!mobile) {
    // All your stuff.
    }
});
于 2012-07-04T21:43:31.233 回答
0

我不建议使用 JavaScript 来检查设备。您在服务器端使用什么?我已经成功地使用了免费的 PHP 移动检测类。它也可以检测移动平板电脑或特定制造商,例如。平板电脑。它也超级容易使用。然后,您可以根据该页面生成页面或重定向到特殊格式的移动网站。使用 javascript 非常不可靠,有些人可能会在浏览器中将其关闭,这不太可能,但它确实发生了。如果您在服务器上执行此操作,则不必担心类似的事情。

于 2012-07-06T02:04:20.653 回答