[dev] How do I use the JS-file caching mechanism of Horde?

Jan Schneider jan at horde.org
Thu Nov 23 16:38:22 UTC 2017


Zitat von Sebastian Birnbach <birnbacs at gmail.com>:

> Followup:
>
>
> I meanwhile figured out the official method for adding JS files:
> Horde_PageOutput::addScriptFile().
>
> Still, I can't seem to make it work.
>
>
> Everything works when the Horde_View file contains
>
> <script type="text/javascript" src="/js/form_sections.js"></script>
>
> But if I replace that with
>
> <?php
> $GLOBALS['page_output']->addScriptFile('form_sections.js', 'horde');
> ?>
>
> I see that the generated HTML code loads a cached version of the js file:
>
> <script type="text/javascript"
> src="/js/form_sections.js?v=596ca0a81b7fe741719c6df2f8b52a22"></script>
>
> only that functionality is negative.
>
>
> In this case, JS console complains about undefined variable
> sections_dossier_form
> which is in fact defined near the bottom of the Horde_View file:
>
> <script type="text/javascript">//<![CDATA[
> var sections_dossier_form = new Horde_Form_Sections('dossier_form',
> 'overview');
> document.observe("dom:loaded",function(){$("horde_form").focusFirstElement();});
> //]]></script>
>
> Any clues, anybody?
>
> 2017-11-23 9:35 GMT+01:00 Sebastian Birnbach <birnbacs at gmail.com>:
>
>> I am playing around with Horde_Views and the Javascript gems in /js, like
>> tables.js or form_sections.js. It is a real pity that there is so little
>> documentation (none at all?) on these.
>>
>> Anyway, I am wondering how to include JS files making use of the Horde JS
>> caching system. For instance, I see in the HTML source of an average Horde
>> page something like
>>
>>   <script type="text/javascript"  
>> src="/js/prototype.js?v=596ca0a81b7fe741719c6df2f8b52a22
>>
>> and I assume that the v=... is a caching key. What would be the proper way
>> to get such a key and denote inclusion of a JS file in a Horde_View with
>> caching support?
>>

You need to call addScriptFile() *before* starting the page output.

-- 
Jan Schneider
The Horde Project
https://www.horde.org/



More information about the dev mailing list