Skip to main content
manifest cache

Cache manifest in drupal

This blog gives you an understanding about cache manifest in Drupal. Cache manifest is used to cache pages in local server to use it when there is no network connection. This can be easily done by adding attribute "manifest="filename.appcache" to the HTML tag as mentioned below:

<html manifest="example.appcache">
..
....
</html>

More details about cache manifest in general can be found here. Creating a manifest file and referring that file in HTML tag is simple and straightforward in normal HTML file. Now the question is, can this be done in Drupal? Yes, of course this is possible.

Another question may arise, cache manifest is in HTML5, will it also work in Drupal site which is not in HTML5.? Again yes to your question, it will work. Just adding manifest attribute to html tag is enough. Let us see this in detail below about how cache manifest can be implemented in Drupal.

There are two ways to do this in Drupal, first by adding manifest value in html_attributes in hook_preprocess_html as mentioned below:

function ThemeName_preprocess_html(&$variables) {
  $variables['html_attributes_array'] = array(
    'manifest' => 'example.appcache',
  );
}
Then it can be added to html by printing the variable $html_attributes in html.tpl.php in the html element.
 
Another way is to add manifest attribute directly to html.tpl.php in the html element. As method one looks more solid with Drupal, I have not covered too much about method 2 in this blog.
 
Hope this blog helps you.

Comments

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.