blog-banner

Cache Manifest in Drupal

  • Drupal
  • HTML5
  • Preprocess
  • Templates

HTML5 Manifest

This blog gives you an understanding of cache manifest in Drupal. Cache manifest is used to cache pages in the 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">
..
....

More details about cache manifest, in general, can be found here. Creating a manifest file and referring to that file in HTML tag is simple and straightforward in the 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 the 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 to 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 attributes 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.
Get awesome tech content in your inbox