Stuff added to  not included in cached version I have a page on drupal 7 where I have the text format set to PHP Code.  I am using the drupal_add_html_head() to include a few CSS/JS files, and an RSS link.  My problem is that everything I add with drupal_add_html_head is only visible for a single view after the caches are cleared.  After that single view they do not show up in the view source.

It can be demonstrated with a Body that is as simple as below.  The first view will show an alert.  If you reload the page, the script is not added, and alert() is not called.

&lt;?php
drupal_add_html_head(array(
  '#tag' =&gt; 'script', 
  '#value' =&gt; 'alert("Hello world!");',
  '#attributes' =&gt; array(
    'type' =&gt; 'text/javascript'
  )
), 'jscripttest');
?&gt;

You should see "Hello world!"  But you don't unless you have just 
cleared the cache.


I have also tried drupal_add_css, and drupal_add_js with similar results.  The CSS/JS is displayed after the cache is cleared, but only once.
This is a totally valid question in my opinion. Using the PHP input filter (or eval() in general) is almost never a good idea, but the fact that this code only runs once is not intuitive.

That said, I actually can't reproduce this.

My first thought was that the rendered HTML was being cached in the cache_filter table. But by default, the PHP Input filter is not cached in the cache_filter table. php_filter_info() from php_module:

function php_filter_info() {
  $filters['php_code'] = array(
    'title' =&gt; t('PHP evaluator'),
    'description' =&gt; t('Executes a piece of PHP code. The usage of this filter should be restricted to administrators only!'),
    'process callback' =&gt; 'php_eval',
    'tips callback' =&gt; '_php_filter_tips',
    'cache' =&gt; FALSE, // &lt;- This is set to FALSE in the module
  );
  return $filters;
}


My next guess was that the anon user Page Cache was somehow ignoring the fact that those functions had been called. But I tested both drupal_add_html_head and drupal_add_js (the latter with both an external file and inline JS) and even for anonymous users, the JS was loaded and executed on all page views with and without the page cache enabled. I also tried all of these scenarios in the default body field and with a field added with the Field API.

I guess that means that my answer is one of the following:


Something is overriding php_filter_info() to set 'cache' =&gt; TRUE
You have an additional layer of caching that's causing this on your server
Something else???