<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[PunBB Forums — [Advice] Multiple extensions using prototype]]></title>
		<link>https://punbb.informer.com/forums/topic/20532/advice-multiple-extensions-using-prototype/</link>
		<atom:link href="https://punbb.informer.com/forums/feed/rss/topic/20532/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in [Advice] Multiple extensions using prototype.]]></description>
		<lastBuildDate>Thu, 26 Feb 2009 11:36:47 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: [Advice] Multiple extensions using prototype]]></title>
			<link>https://punbb.informer.com/forums/post/125032/#p125032</link>
			<description><![CDATA[<p>Does this solution still work if the extension developer wants to put the js library at the end of the page so it doesn&#039;t stall the loading of the page?</p>]]></description>
			<author><![CDATA[null@example.com (slickplaid)]]></author>
			<pubDate>Thu, 26 Feb 2009 11:36:47 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/125032/#p125032</guid>
		</item>
		<item>
			<title><![CDATA[Re: [Advice] Multiple extensions using prototype]]></title>
			<link>https://punbb.informer.com/forums/post/120947/#p120947</link>
			<description><![CDATA[<p>This good idea.<br />I have made extension jsHelper. The same idea - to prevent collisions.<br />Except for it&nbsp; jsHelper solved other task - to include a js-script in html-header at any time generating of a content. Use hook hd-head and in general anyone hooks from header.php narrows opportunities of the developer. It happens it is necessary to include a js-script already after header.php has been caused.<br /> jsHelper extension solves also this problem too.<br />That it worked, it is necessary to have js-scripts in one directory on server, for example <strong>root/js/</strong><br />It should become the agreement. </p><p>Example of connection jquery:<br /></p><div class="codebox"><pre><code>$jsHelper-&gt;add ($base_url.&#039;/js/jquery.js&#039;);</code></pre></div><p>Some extensions, can&nbsp; make this call.<br />In html-header will be only once:<br /></p><div class="codebox"><pre><code>&lt;script type = &quot;text/javascript&quot; src = &quot;http://example.forum/js/jquery.js&quot;&gt; &lt;/script&gt;</code></pre></div><p>Try extension: <a href="http://punbb.ru/downloads/jshelper.zip">http://punbb.ru/downloads/jshelper.zip</a> (1kb)</p><p>sorry my english</p>]]></description>
			<author><![CDATA[null@example.com (hcs)]]></author>
			<pubDate>Sun, 14 Dec 2008 15:08:53 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/120947/#p120947</guid>
		</item>
		<item>
			<title><![CDATA[Re: [Advice] Multiple extensions using prototype]]></title>
			<link>https://punbb.informer.com/forums/post/120911/#p120911</link>
			<description><![CDATA[<p>Coming up with a list of commonly-used libraries and assigning each one of them a common name would help even more.</p><p>Here&#039;s a list of JS frameworks/libraries: <a href="http://ntt.cc/2008/02/13/the-most-complete-ajax-framework-and-javascript-libraries-list.html">http://ntt.cc/2008/02/13/the-most-compl … -list.html</a></p>]]></description>
			<author><![CDATA[null@example.com (User33)]]></author>
			<pubDate>Sat, 13 Dec 2008 22:25:34 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/120911/#p120911</guid>
		</item>
		<item>
			<title><![CDATA[[Advice] Multiple extensions using prototype]]></title>
			<link>https://punbb.informer.com/forums/post/120892/#p120892</link>
			<description><![CDATA[<p>Sharing some thought to other extension developers...</p><div class="codebox"><pre><code>&lt;hook id=&quot;hd_head&quot;&gt;&lt;![CDATA[
    $forum_head[&#039;ex1_prototype&#039;] = &#039;&lt;script type=&quot;text/javascript&quot; src=&quot;&#039;.$ext_info[&#039;url&#039;].&#039;/media/js/prototype.js&quot;&gt;&lt;/script&gt;&#039;;
]]&gt;&lt;/hook&gt;
-------
&lt;hook id=&quot;hd_head&quot;&gt;&lt;![CDATA[
    $forum_head[&#039;ex2_prototype&#039;] = &#039;&lt;script type=&quot;text/javascript&quot; src=&quot;&#039;.$ext_info[&#039;url&#039;].&#039;/media/js/prototype.js&quot;&gt;&lt;/script&gt;&#039;;
]]&gt;&lt;/hook&gt;</code></pre></div><p>I&#039;ve come across a problem while developing an extension: what if both of them require prototype (javascript framework). Adding it twice is not only a waste, but would most likely provokes bunch of bugs, I could separate it as a third extension that others would require to run, but this is bothersome for users.<br />Looking at how js files are added to the header I finally found a satisfying work around.</p><br /><div class="codebox"><pre><code>&lt;hook id=&quot;hd_head&quot;&gt;&lt;![CDATA[
    $forum_head[&#039;prototypejs&#039;] = &#039;&lt;script type=&quot;text/javascript&quot; src=&quot;&#039;.$ext_info[&#039;url&#039;].&#039;/media/js/prototype.js&quot;&gt;&lt;/script&gt;&#039;;
]]&gt;&lt;/hook&gt;
-------
&lt;hook id=&quot;hd_head&quot;&gt;&lt;![CDATA[
    $forum_head[&#039;prototypejs&#039;] = &#039;&lt;script type=&quot;text/javascript&quot; src=&quot;&#039;.$ext_info[&#039;url&#039;].&#039;/media/js/prototype.js&quot;&gt;&lt;/script&gt;&#039;;
]]&gt;&lt;/hook&gt;</code></pre></div><p>First we need to choose a single name for prototype across all extensions, I took &quot;prototypejs&quot;.<br />This way, no matter how many extensions add it, only one file will be loaded because the last extension will override previous value for the &quot;prototypejs&quot; key.</p><br /><div class="codebox"><pre><code>&lt;hook id=&quot;hd_head&quot;&gt;&lt;![CDATA[
    $forum_head[&#039;prototypejs&#039;] = &#039;&lt;script type=&quot;text/javascript&quot; src=&quot;&#039;.$ext_info[&#039;url&#039;].&#039;/media/js/prototype.js&quot;&gt;&lt;/script&gt;&#039;;
]]&gt;&lt;/hook&gt;
-------
&lt;hook id=&quot;hd_head&quot;&gt;&lt;![CDATA[
if(FORUM_PAGE === &#039;index&#039;) {
    $forum_head[&#039;prototypejs&#039;] = &#039;&lt;script type=&quot;text/javascript&quot; src=&quot;&#039;.$ext_info[&#039;url&#039;].&#039;/media/js/prototype.js&quot;&gt;&lt;/script&gt;&#039;;
}
]]&gt;&lt;/hook&gt;</code></pre></div><p>One problem remains, let&#039;s imagine 2 extensions, one run only on index and the other applies on each page. The index one is parsed last. We would have 2 different files loaded depending on the page. This is a waste of time, bandwidth and cache.</p><br /><div class="codebox"><pre><code>&lt;hook id=&quot;hd_head&quot;&gt;&lt;![CDATA[
    $forum_head[&#039;prototypejs&#039;] = &#039;&lt;script type=&quot;text/javascript&quot; src=&quot;&#039;.$ext_info[&#039;url&#039;].&#039;/media/js/prototype.js&quot;&gt;&lt;/script&gt;&#039;;
]]&gt;&lt;/hook&gt;
-------
&lt;hook id=&quot;hd_head&quot;&gt;&lt;![CDATA[
if(FORUM_PAGE === &#039;index&#039;) {
    if(!isset($forum_head[&#039;prototypejs&#039;])) { $forum_head[&#039;prototypejs&#039;] = &#039;&lt;script type=&quot;text/javascript&quot; src=&quot;&#039;.$ext_info[&#039;url&#039;].&#039;/media/js/prototype.js&quot;&gt;&lt;/script&gt;&#039;;}
}
]]&gt;&lt;/hook&gt;
-------
&lt;hook id=&quot;hd_head&quot; priority=&quot;4&quot;&gt;&lt;![CDATA[
if(FORUM_PAGE === &#039;index&#039;) {
    $forum_head[&#039;prototypejs&#039;] = &#039;&lt;script type=&quot;text/javascript&quot; src=&quot;&#039;.$ext_info[&#039;url&#039;].&#039;/media/js/prototype.js&quot;&gt;&lt;/script&gt;&#039;;
}
]]&gt;&lt;/hook&gt;</code></pre></div><p>There&#039;s two way to solve this, either up the priority of the index&#039;s extension so it runs first, either add a condition to not override already existing prototypejs key.</p><br /><p>That&#039;s all, hope it may be helpful to someone. It can applies to lot of things you wish to include only once across many extensions <img src="https://punbb.informer.com/forums/img/smilies/wink.png" width="15" height="15" alt="wink" /></p>]]></description>
			<author><![CDATA[null@example.com (Neck)]]></author>
			<pubDate>Sat, 13 Dec 2008 18:49:54 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/120892/#p120892</guid>
		</item>
	</channel>
</rss>
