I am creating a module that has a page that is intended to be a viewer for a certain kind of content. The content itself is a Drupal Book viewer meant to behave like an epub reader. Basically I want this page to be a stand-alone, theme-independent, full-screen "player."

To achieve this effect, I don't want to load the usual long list of CSS and JS files, including those from the current theme as well as any from modules that I am not interested in using. I want the page to load only those JS and CSS files that are required for basic Drupal functionality -- e.g. I want Behaviors to work and a few other things, such as overlays.

My question is, what are considered to be the essential JS and CSS files? I realize I can find a way to just dump a list of all files by module. But I am looking for information on importance. I realize this is a little vague and that there are probably a lot of answers that begin with "It depends ..." However, there must be some items that are more fundamental than others.

I am working in Drupal 7 and using hook_js_alter() and hook_css_alter() to remove (unset) items, and a preprocess function to add items.

  • 2
    Welcome to Drupal Answers :) It's not really possible to answer this at the moment - specific things you want/don't want will be in specific JS/CSS files, so without knowing everything you consider as "required" (bearing in mind no CSS or JS is actually required to view an HTML page) I don't know how people will be able to respond – Clive Jun 2 '14 at 19:40
  • Clive -- yes, I thought this would be the case. I guess the thing to do is to determine the functionality one needs, and then to find the CSS and JS files associated with the modules that provide that functionality. – ontoligent Jun 3 '14 at 21:26
  • Painful work, but yeah, I think that's your best option really – Clive Jun 3 '14 at 21:43

You can achieve this by making your module load your own html.tpl.php and in that version of the html template, you simply remove references to styles and scripts.

<?php print $styles; ?>
<?php print $scripts; ?>

For a viewer, you can probably do without the reams of CSS cruft that is loaded by default and add your own bare bones css & js either through a hook or by including it in your custom html template.

<?php print $path_to_your_reader_styles; ?>
<?php print $path_to_your_reader_scripts; ?>
| improve this answer | |

The answer to this question is that there is no answer. As Clive comments, it depends on what you are doing -- or, more specifically, what your base modules are and which theme you are using. At the moment, there is no registry to look at which will tell you all of the JS files and CSS files you are using, but I suppose one can achieve this effect by setting up a pristine site with all of the basic stuff and, before adding anything, inspecting the js and css arrays.

| improve this answer | |

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