htmlhead with cached events

I am trying to build a general purpose plugin that will take either an
Array or JSON data and display it on a google map. All is going well,
except for one thing:

I am using addAsset() and htmlhead() to add code into the head.
Problem is when the event is cached, the js is not inserted into the
head (because cfhtmlhead is not called)

Am I stuck with including the code in the body? That would work, but
would cause a few issues off the top of my head:
1. Have to make sure not to include code more than once
2. It hurts my head to include so much js in the middle of a page
3. It will make having multiple maps on one page harder to manage

Am I not thinking of something? Anyone have ideas?

Thanks,

No Ken, the problem is that event caching only looks at what the HTML that’s produced. HTMLHEAD is this nasty place that CF has that you don’t have access to (officially, unless you poke around). So unfortuantely the event caching mechanisms kinda are screwed there, unless you can bring in the content dynamically via ajax or JS includes, then you can.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

If the CFHtmlHead is in the view why would it duplicate the JS?

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Ken Smith
Sent: Friday, 10 September 2010 6:32 AM
To: ColdBox Platform
Subject: [coldbox:5670] htmlhead with cached events

I am trying to build a general purpose plugin that will take either an

Array or

JSON data and display it on a google map. All is going well, except for

one

thing:

I am using addAsset() and htmlhead() to add code into the head.
Problem is when the event is cached, the js is not inserted into the head
(because cfhtmlhead is not called)

Am I stuck with including the code in the body? That would work, but

would

Event caching stores the HTML produced from that event only. Since
the cfHtmlHead injects into the head (outside of the produced HTML),
it is not included as part of the event's HTML. The next time you run
the cached page, the view doesn't fire, so the cfHtmlHead doesn't
fire. It sucks, but it makes sense.

This is one solution I'm looking into, although it feels
"hacky" (although i don't know why...)

function include_dom(script_filename) {
var html_doc = document.getElementsByTagName('head').item(0);
var js = document.createElement('script');
js.setAttribute('language', 'javascript');
js.setAttribute('type', 'text/javascript');
js.setAttribute('src', script_filename);
html_doc.appendChild(js);
return false;
}

Really, I have cached events and custom tags to generate a grid and some
other things. They use the cfhtmlhead extensively. The custom tags are only
in my views, the only thing I can think of here is that my layout is not
cached.

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Ken Smith
Sent: Saturday, 11 September 2010 12:33 AM
To: ColdBox Platform
Subject: [coldbox:5694] Re: htmlhead with cached events

Event caching stores the HTML produced from that event only. Since the
cfHtmlHead injects into the head (outside of the produced HTML), it is not
included as part of the event's HTML. The next time you run the cached
page, the view doesn't fire, so the cfHtmlHead doesn't fire. It sucks,

but it

makes sense.

This is one solution I'm looking into, although it feels "hacky" (although

i don't

know why...)

function include_dom(script_filename) {
var html_doc = document.getElementsByTagName('head').item(0);
var js = document.createElement('script'); js.setAttribute('language',
'javascript'); js.setAttribute('type', 'text/javascript');

js.setAttribute('src',