1

I have a site that also serves its content to mobile devices. As these sites(desktop/mobile) uses same code. I have a problem in performance since the modules being used in desktop site is also loaded in mobile site even if I'm not using it. Is there a way to excludes those modules(custom/contrib) without hacking each modules? Any good idea in this kind of situation?

Hi Patrick...something like this code I created so far...but I'm not sure if this is feasible.

function array_search_regex($pattern, $array) {
        for($x = 0; $x < count($array); $x++) {
            if(preg_match($pattern, $array[$x])) {
                return true;
            }
        }
      return false;
  }

  //Collect all css and place in an array
    $get_all_css = array();
    $get_all_css = drupal_get_css();

    //Put the return html styles in an array
    $ret_all_css = explode("\n", $get_all_css);
    //Get the array index of the matched in the search
    //$lookup_css = array_search('<link type="text/css" rel="stylesheet" media="all" href="/modules/node/node.css?G" />', $ret_all_css);
    $lookup_css = array_search_regex("/<link type=\"text\/css\" rel=\"stylesheet\" media=\"all\" href=\"\/modules\/node\/node.css\?.\" \/>/", $ret_all_css);

    //Unset the searched styles. 
    unset($ret_all_css[$lookup_css]);

    //Return all essential styles. This should replace $styles in page.tpl.php
    $styles = implode("\n", $ret_all_css);

2 Answers 2

3

The load caused by modules is handled by the server, so merely having the modules enabled will not affect the performance of your mobile site. In any case, it is impossible to disable the modules because you could be serving web pages to both mobile and desktop machines at the same time.

Instead, what you want to do is add a mobile theme. There are lots of ways to do this but the Mobile Tools module is a good way to get started.

For a more specific solution, you'll have to identify which modules are causing the performance problems on your site so that workarounds can be found.

6
  • Hi Patrick...sorry about the confusion. I mean just exclude those javascript and css since they are not needed in mobile site. Those files declared in the module hook_init() via drupal_add_js and drupal_add_css. I manage to exclude all custom modules but I'm not sure about contrib since as a rule we are not allowed to touch contributed modules unless patch it and submit in the community but my case is different. Thanks Commented May 7, 2012 at 7:18
  • Also I'm using different theme. I used $theme as a condition so I can load all those custom modules for desktop if the active theme is the desktop theme. Commented May 7, 2012 at 7:24
  • I don't understand what you're trying to do. If you don't want css to load, you can unset the css in the theme. However, you should not be enabling or disabling modules on the fly; that will break your site. Commented May 7, 2012 at 7:30
  • Hi Patrick...see the above update I made. Commented May 8, 2012 at 5:55
  • 1
    On this site, you should not edit your question to replace it with a different question. If you do this, it will break the search on the site for other users because the title of your question will be completely different than the content. If you want to ask a new question about resetting CSS, ask a new question; do not add it to this question, which is about how to disable modules. Commented May 8, 2012 at 6:12
1

I can see you don't mind having your hands dirty coding but I suggest to check out available Drupal responsive themes. These automatically recognize the user's device and can provide separate css based on that. I use drupal.org/project/omega and http://drupal.org/project/adaptivetheme.

1
  • Thanks for this good suggestion refineo. But switching a theme is not an option. The site I'm working is really big and the management don't require to change the theme. The only option is to create a code that will exclude desktop css and js. Commented May 8, 2012 at 6:32

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.