<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: &lt;%= javascript_include_tag :defaults %&gt; considered harmful?</title>
	<atom:link href="http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/feed/" rel="self" type="application/rss+xml" />
	<link>http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/</link>
	<description>a weblog by Tom Armitage</description>
	<lastBuildDate>Tue, 09 Mar 2010 21:07:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Steven G. Harms</title>
		<link>http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/comment-page-1/#comment-61366</link>
		<dc:creator>Steven G. Harms</dc:creator>
		<pubDate>Thu, 03 Jan 2008 14:39:59 +0000</pubDate>
		<guid isPermaLink="false">http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/#comment-61366</guid>
		<description>Why not define a &quot;lite&quot; layout and then the full :defaults &quot;heavy&quot; layout?

&lt;code&gt;
class myController &lt; ApplicationController
 layout :lite_on_js
 def new 
   ...
  end
...
end
&lt;/code&gt;

If doing the JS-lite is more common, change the default layout for that controller to use a layout that includes no JS, then you could manually trigger a JS heavy layout when you needed the kitchen sink with :defaults by using:

&lt;code&gt;
render :layout=&gt;:js_heavy
&lt;/code&gt;

It&#039;s just another way to go, but needlessly including kbs of un-used JS is certainly Not Right (tm).

sgh</description>
		<content:encoded><![CDATA[<p>Why not define a &#8220;lite&#8221; layout and then the full :defaults &#8220;heavy&#8221; layout?</p>
<p><code><br />
class myController &lt; ApplicationController<br />
 layout :lite_on_js<br />
 def new<br />
   ...<br />
  end<br />
...<br />
end<br />
</code></p>
<p>If doing the JS-lite is more common, change the default layout for that controller to use a layout that includes no JS, then you could manually trigger a JS heavy layout when you needed the kitchen sink with :defaults by using:</p>
<p><code><br />
render :layout=&gt;:js_heavy<br />
</code></p>
<p>It&#8217;s just another way to go, but needlessly including kbs of un-used JS is certainly Not Right &#8482;.</p>
<p>sgh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marco</title>
		<link>http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/comment-page-1/#comment-50398</link>
		<dc:creator>Marco</dc:creator>
		<pubDate>Wed, 24 Oct 2007 12:52:54 +0000</pubDate>
		<guid isPermaLink="false">http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/#comment-50398</guid>
		<description>Yes, is very harmful, I had tag default to my application.rhtml, now I had removed this tag and my application is very more speed .</description>
		<content:encoded><![CDATA[<p>Yes, is very harmful, I had tag default to my application.rhtml, now I had removed this tag and my application is very more speed .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nerdmaster</title>
		<link>http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/comment-page-1/#comment-41223</link>
		<dc:creator>Nerdmaster</dc:creator>
		<pubDate>Thu, 16 Aug 2007 19:10:03 +0000</pubDate>
		<guid isPermaLink="false">http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/#comment-41223</guid>
		<description>If you use these JS pages in one central place, it really won&#039;t hurt you to use them everywhere.  A one-time hit of 150k is bad if you don&#039;t need it anywhere in your app, but let&#039;s not forget that browser caching means it is indeed just a one-time hit (check your logs, but in my case anything in public/ is cached nicely).

Be careful how much garbage you include, but don&#039;t try to optimize every single page hit when the browser is specifically built to be efficient at &quot;retrieving&quot; the same static content multiple times.</description>
		<content:encoded><![CDATA[<p>If you use these JS pages in one central place, it really won&#8217;t hurt you to use them everywhere.  A one-time hit of 150k is bad if you don&#8217;t need it anywhere in your app, but let&#8217;s not forget that browser caching means it is indeed just a one-time hit (check your logs, but in my case anything in public/ is cached nicely).</p>
<p>Be careful how much garbage you include, but don&#8217;t try to optimize every single page hit when the browser is specifically built to be efficient at &#8220;retrieving&#8221; the same static content multiple times.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Including Javascript &#171; Ruby on Rails Development on Windows</title>
		<link>http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/comment-page-1/#comment-27264</link>
		<dc:creator>Including Javascript &#171; Ruby on Rails Development on Windows</dc:creator>
		<pubDate>Fri, 09 Mar 2007 18:56:35 +0000</pubDate>
		<guid isPermaLink="false">http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/#comment-27264</guid>
		<description>[...] That includes all these Javascript files though: application.js, controls.js, dragdrop.js, effects.js, prototype.js. All those files add about 150K(?) of code, so if you want to trim it down, you can specify the exact files you need instead of including all of them, e.g., javascript_include_tag &quot;application&quot;, &quot;prototype&quot; [...]</description>
		<content:encoded><![CDATA[<p>[...] That includes all these Javascript files though: application.js, controls.js, dragdrop.js, effects.js, prototype.js. All those files add about 150K(?) of code, so if you want to trim it down, you can specify the exact files you need instead of including all of them, e.g., javascript_include_tag &#8220;application&#8221;, &#8220;prototype&#8221; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Houghton</title>
		<link>http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/comment-page-1/#comment-6657</link>
		<dc:creator>Michael Houghton</dc:creator>
		<pubDate>Fri, 15 Sep 2006 20:32:58 +0000</pubDate>
		<guid isPermaLink="false">http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/#comment-6657</guid>
		<description>ugh, html tags swallowed:

&lt;% if load_page_support? :image_search -%&gt;
  &lt;%= javascript_include_tag &quot;image_search&quot; %&gt;
  ....
&lt;% end -%&gt;</description>
		<content:encoded><![CDATA[<p>ugh, html tags swallowed:</p>
<p>&lt;% if load_page_support? :image_search -%&gt;<br />
  &lt;%= javascript_include_tag &#8220;image_search&#8221; %&gt;<br />
  &#8230;.<br />
&lt;% end -%&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Houghton</title>
		<link>http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/comment-page-1/#comment-6656</link>
		<dc:creator>Michael Houghton</dc:creator>
		<pubDate>Fri, 15 Sep 2006 20:31:40 +0000</pubDate>
		<guid isPermaLink="false">http://infovore.org/archives/2006/07/11/javascript_include_tag-defaults-considered-harmful/#comment-6656</guid>
		<description>I use a conditional loading trick that helps me keep down the load times for users not visiting parts of my site that need particular features.

Basically, these two helper functions allow templates and helpers to identify their layout requirements:

# a way of identifying features the layout needs to load
def require_page_support(*scr)
  @page_scripts &#124;&#124;= {}
  scr.each { &#124;s&#124; @page_scripts[s] = true }
end

# used in the layout to query the need for features
def load_page_support?(*scr)
  @page_scripts &#124;&#124;= {}
  scr.inject(false) {&#124;matches, s&#124; matches &#124;&#124; @page_scripts[s] }
end

Then I can do things like this, in a helper or view:

require_page_support :image_search

And in the layout, that can be serviced by:


  
  ....


This way I force myself to think about the code required for site functions, rather than just blanketing myself in javascript (and other things) that I might not need.</description>
		<content:encoded><![CDATA[<p>I use a conditional loading trick that helps me keep down the load times for users not visiting parts of my site that need particular features.</p>
<p>Basically, these two helper functions allow templates and helpers to identify their layout requirements:</p>
<p># a way of identifying features the layout needs to load<br />
def require_page_support(*scr)<br />
  @page_scripts ||= {}<br />
  scr.each { |s| @page_scripts[s] = true }<br />
end</p>
<p># used in the layout to query the need for features<br />
def load_page_support?(*scr)<br />
  @page_scripts ||= {}<br />
  scr.inject(false) {|matches, s| matches || @page_scripts[s] }<br />
end</p>
<p>Then I can do things like this, in a helper or view:</p>
<p>require_page_support :image_search</p>
<p>And in the layout, that can be serviced by:</p>
<p>  &#8230;.</p>
<p>This way I force myself to think about the code required for site functions, rather than just blanketing myself in javascript (and other things) that I might not need.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
