Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I use drupal 6 and ubercart2. Loading of cart and checkout page takes a while so I am thinking about removing any js and css files which are not used on specific pages. What would be the ideal way to do it? I know about js agregation but want to try the first approach. Thank you very much.

share|improve this question
Just a side note, but the combination of JS/CSS aggregation with proper cache headers (or origin pull CDN) can really make a site fly. Look at the .htaccess fro HTML5 Boilerplate for inspiration. – MPD Nov 25 '12 at 0:11

2 Answers

Have a look at the FOAD technique to get rid of stylesheets and scripts. It happens in your own theme.

You can take an alternate route and use stuff like Stylestripper module or Mothership base theme.

share|improve this answer

With reference to your question 'optimal way to remove unwanted js and css files from page', hope this approach works ::

1) Include your js & css files only under appropriate hook as per applicable

2) Use syntax like -

drupal_add_js (drupal_get_path ('module', 'module_name') . '/js/js_file_name.js' ); drupal_add_css(drupal_get_path('module', 'module_name') . '/css/css_file_name.css');

3) You can make use of syntax like this to set some settings variable & check in your js file before invoking your event inside the behavior

In module file ::

drupal_add_js (array ('module_name' => array ('variable_name' => some_value)), 'setting' );

In js file ::


   Drupal.behaviors.testName = {
     attach: function (context, settings) {
       if(typeof Drupal.settings.module_name != 'undefined' 
    && 
    Drupal.settings.module_name.variable_name == some_value){
      // Do SOMETHING
       }
     }
  };

4) If your code already included js & css files at places which could be done a better way, then you need to make the code changes accordingly. For example,

If we could include the js & css files in hook_node_view (based on D7 standard, say), then we should not include it from hook_init.

Hope it helps

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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