<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tech Insight ! &#187; HTML</title>
	<atom:link href="http://techinsight.dhanashree.com/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://techinsight.dhanashree.com</link>
	<description>Technical blog on ASP.Net, PHP, Web Development, Web hosting , Database Programming</description>
	<lastBuildDate>Fri, 12 Aug 2011 07:26:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Combine/Compress/Minify JavaScript, CSS in Asp.net</title>
		<link>http://techinsight.dhanashree.com/combinecompressminify-javascript-css-in-asp-net/</link>
		<comments>http://techinsight.dhanashree.com/combinecompressminify-javascript-css-in-asp-net/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 11:00:28 +0000</pubDate>
		<dc:creator>kiran</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[.net framework]]></category>
		<category><![CDATA[CSS 3]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Web Developement]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[.net developement]]></category>
		<category><![CDATA[asp.net developement]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://techinsight.dhanashree.com/combinecompressminify-javascript-css-in-asp-net/</guid>
		<description><![CDATA[Introduction:

When we design and develop the website, the performance is in the core of development. The system you are developing must produce the result with high speed. For the web development perspective, website load performance is very essential thing to take care of. You need good working layout, easy layout and easy navigation.
Here with this [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction:<br />
</strong></p>
<p>When we design and develop the website, the performance is in the core of development. The system you are developing must produce the result with high speed. For the web development perspective, website load performance is very essential thing to take care of. You need good working layout, easy layout and easy navigation.</p>
<p>Here with this article I m not going to talk about of all the aspects of web application performance improvements. But I am specifically targeting the topic when it comes to the CSS and JavaScript faster loading in the client browser.  In fact Google is also counting the speed of your website site when indexing to your website.</p>
<p>The goal was to improve overall performance on the client side. At the same time, it will show how we can force a client side script to be coached at the browser, so that in subsequent visit, it will take those scripts from the cache. This becomes increasingly important when using AJAX techniques within an application that introduce new features and functionality.</p>
<p>First of all I will outline the requirements and essential steps that this project is made of. So that if you want to implement the same in your development, it become easy for you to set up project.</p>
<p>To download complete project, <a href="http://www.esnips.com/doc/bb247398-9971-4fac-bb8e-02a8e8ebad7d/JS-CSS-Combiner-Minifier">click here</a></p>
<p><strong>Setup:<br />
</strong></p>
<p>To begin with, we will have following list of files to be created in the development studio.</p>
<ol>
<li>2 XML files, first one to hold source of JS files for each page and second to  hold CSS files for each page.</li>
<li>A generic class that implement <em>IHttpHandler, </em>that will be used to delivery combined and compressed JavaScript/CSS at the client.</li>
<li>And at last your .ASPX file that will be used to serve combined and compressed Javascript/CSS at client side.</li>
</ol>
<p><strong>Step by Step Implementation:<br />
</strong></p>
<p>Now let&#8217;s get dig into the actual development. To summarize, let&#8217;s say we have a page default.aspx that has following no. of JavaScript files and CSS files. Think of these file that we wanted to combine them and deliver at one go at the client browser.</p>
<ol>
<li>jquery.js</li>
<li>script-file-1.js</li>
<li>style-1.css</li>
<li>style-2.css</li>
</ol>
<p>As you can see, we have 2 different JavaScript file &amp; 2 CSS files. So what basically we will do in the next is to create a utility which can combine given JavaScript and compress it, then send it to client browser. Next the same process will be done for the CSS. Both the CSS files will be combined and compressed and send to client browser.</p>
<p>Now it&#8217;s time to take a look at into actual stuff that does this underlying work.</p>
<p>First of all we will create a CS class file that will hold the programming stuffs.</p>
<p>So perform the following steps to create &amp; configure that CS class file.</p>
<ol>
<li>
<div>Create CS class file with the name <em>ScriptCombiner.cs</em> and put the following code in that.</div>
</li>
</ol>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">public</span><span style="color: blue;"> </span><span style="color: blue;">class</span><br />
<span style="color: #2b91af;">ScriptCombiner</span> : <span style="color: #2b91af;">IHttpHandler<span style="color: #000000;">{</span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">private</span><span style="color: blue;"> </span><span style="color: blue;">readonly</span><span style="color: blue;"> </span><span style="color: blue;">static</span><span style="color: blue;"> </span><span style="color: #2b91af;">TimeSpan</span> CACHE_DURATION = <span style="color: #2b91af;">TimeSpan</span>.FromDays(1);</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">private</span><span style="color: blue;"> </span><span style="color: #2b91af;">HttpContext</span> context;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">public</span><span style="color: blue;"> </span><span style="color: blue;">void</span> ProcessRequest(<span style="color: #2b91af;">HttpContext</span> context){</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">public</span><span style="color: blue;"> </span><span style="color: blue;">bool</span> IsReusable{</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">get</span> { <span style="color: blue;">return</span><span style="color: blue;"> </span><span style="color: blue;">true</span>; }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">}</span></p>
<p>As you can see, we are implementing the <span style="color: #2b91af; font-family: Courier New; font-size: 10pt;">IHttpHandler </span>interface.</p>
<p>You can write custom HTTP handlers to process specific, predefined types of HTTP requests in any Common Language Specification (CLS) compliant language. Executable code defined in the HttpHandler classes, rather than conventional ASP or ASP.NET Web pages, responds to these specific requests. HTTP handlers give you a means of interacting with the low-level request and response services of the IIS Web server and provide functionality much like ISAPI extensions but with a simpler programming model.</p>
<p>We are also implementing <span style="font-family: Courier New; font-size: 10pt;">IsReusable </span>properly as it is compulsory to implement as a part of inheritance of <span style="color: #2b91af; font-family: Courier New; font-size: 10pt;">IHttpHandler </span>interface.</p>
<p>Now, let&#8217;s put the nuts &amp; bolts inside the <span style="font-family: Courier New; font-size: 10pt;">ProcessRequest </span>function. I will also explain you the step by step each execution that is inside this function.</p>
<ol>
<li>We will also create another CS class file that is used to compress JavaScript. That file is named as &#8220;JavaScriptMinifier.cs&#8221;. Please take a look at the attached project solution file. As it is contain long lines of code, I can&#8217;t put it here.</li>
<li>Complete your class file with following functions.</li>
</ol>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">public</span><span style="color: blue;"> </span><span style="color: blue;">void</span> ProcessRequest(<span style="color: #2b91af;">HttpContext</span> context)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">string</span> xStrType, xStrSet, xStrVer, xStrpagecode;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: #2b91af;">Boolean</span> xBlnCanCompress;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">this</span>.context = context;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: #2b91af;">HttpRequest</span> request = context.Request;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">xStrType = (!<span style="color: #2b91af;">String</span>.IsNullOrEmpty(request[<span style="color: #a31515;">"type"</span>])) ? request[<span style="color: #a31515;">"type"</span>] : <span style="color: blue;">null</span>;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> xStrSet = (!<span style="color: #2b91af;">String</span>.IsNullOrEmpty(request[<span style="color: #a31515;">"s"</span>])) ? request[<span style="color: #a31515;">"s"</span>] : <span style="color: blue;">null</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> xStrVer = (!<span style="color: #2b91af;">String</span>.IsNullOrEmpty(request[<span style="color: #a31515;">"v"</span>])) ? request[<span style="color: #a31515;">"v"</span>] : <span style="color: blue;">null</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> xStrpagecode = (!<span style="color: #2b91af;">String</span>.IsNullOrEmpty(request[<span style="color: #a31515;">"pcode"</span>])) ? request[<span style="color: #a31515;">"pcode"</span>] : <span style="color: blue;">null</span>;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">//first check if client browser can support compressions<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> xBlnCanCompress = CanClientGZip(request);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">using</span> (<span style="color: #2b91af;">MemoryStream</span> memStream = <span style="color: blue;">new</span><span style="color: blue;"> </span><span style="color: #2b91af;">MemoryStream</span>(8092))<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: #2b91af;">Stream</span> writer;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">//if browser is supporing GZip compression then create a new object using ICSharpCode.SharpZipLib.GZip</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">//library which allow the compressed respose to send to client<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (xBlnCanCompress) </span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">writer = (<span style="color: blue;">new</span> ICSharpCode.SharpZipLib.GZip.GZipOutputStream(memStream));</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> writer = memStream;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">using</span> (writer){</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: green;">//now its time to read all the script/css files into a StringBuilder object.<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: #2b91af;">StringBuilder</span> combinedSource = <span style="color: blue;">new</span><span style="color: blue;"> </span><span style="color: #2b91af;">StringBuilder</span>();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">foreach</span> (<span style="color: blue;">string</span> file <span style="color: blue;">in</span> GetFileNames(xStrSet, xStrpagecode, xStrType))<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> combinedSource.Append(System.IO.<span style="color: #2b91af;">File</span>.ReadAllText(context.Server.MapPath(file), <span style="color: #2b91af;">Encoding</span>.UTF8));<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: green;">//Upto now we have combined all css/javascript based on request.<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: green;">//its now time to remove extra white spaces and other unwanted characters from respose.</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">//compression will take place now.<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">string</span> minified;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">//use the YUI Javascript/CSS minifier to compress all js files<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (xStrType == <span style="color: #a31515;">&#8220;js&#8221;</span>)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> minified = combinedSource.ToString();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> minified = CompressCSS(combinedSource.ToString());<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: green;">// Send minfied string to output stream<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">byte</span>[] bt = <span style="color: #2b91af;">Encoding</span>.UTF8.GetBytes(minified);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> writer.Write(bt, 0, bt.Length);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">//cache the respose so that in next request it can be reused<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">byte</span>[] responseBytes = memStream.ToArray();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: green;">//context.Cache.Insert(GetCacheKey(xStrSet, xStrType, xStrVer, xBlnCanCompress), responseBytes, null, System.Web.Caching.Cache.NoAbsoluteExpiration, CACHE_DURATION);<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: green;">// Generate the response<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">this</span>.WriteBytes(responseBytes, xBlnCanCompress, xStrType);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">private</span><span style="color: blue;"> </span><span style="color: blue;">bool</span> CanClientGZip(<span style="color: #2b91af;">HttpRequest</span> request){</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">string</span> acceptEncoding = request.Headers[<span style="color: #a31515;">"Accept-Encoding"</span>];<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (!<span style="color: blue;">string</span>.IsNullOrEmpty(acceptEncoding) &amp;&amp;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> (acceptEncoding.Contains(<span style="color: #a31515;">&#8220;gzip&#8221;</span>) || acceptEncoding.Contains(<span style="color: #a31515;">&#8220;deflate&#8221;</span>)))<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">return </span><span style="color: blue;">true</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">return</span><span style="color: blue;"> </span><span style="color: blue;">false</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">// helper method that return an array of file names inside the text file stored in App_Data folder<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">private</span><span style="color: blue;"> </span><span style="color: blue;">static</span><span style="color: blue;"> </span><span style="color: blue;">string</span>[] GetFileNames(<span style="color: blue;">string</span> setName, <span style="color: blue;">string</span> pagecode, <span style="color: blue;">string</span> type)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {System.Xml.XPath.<span style="color: #2b91af;">XPathDocument</span> doc2;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> System.Xml.XPath.<span style="color: #2b91af;">XPathNavigator</span> navigator;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> System.Xml.XPath.<span style="color: #2b91af;">XPathNodeIterator</span> iterator;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> System.Collections.Generic.<span style="color: #2b91af;">List</span>&lt;<span style="color: blue;">string</span>&gt; scripts = <span style="color: blue;">new</span> System.Collections.Generic.<span style="color: #2b91af;">List</span>&lt;<span style="color: blue;">string</span>&gt;();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">string</span> key;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">if</span> (type == <span style="color: #a31515;">&#8220;js&#8221;</span>)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> key = <span style="color: #a31515;">&#8220;scriptfile&#8221;</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> key = <span style="color: #a31515;">&#8220;cssfile&#8221;</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (System.Web.<span style="color: #2b91af;">HttpContext</span>.Current.Cache[key] != <span style="color: blue;">null</span>)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {doc2 = (System.Xml.XPath.<span style="color: #2b91af;">XPathDocument</span>)System.Web.<span style="color: #2b91af;">HttpContext</span>.Current.Cache[key];</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">string</span> filename;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> filename = System.Web.<span style="color: #2b91af;">HttpContext</span>.Current.Server.MapPath(<span style="color: #2b91af;">String</span>.Format(<span style="color: #a31515;">&#8220;~/App_Data/{0}.xml&#8221;</span>, setName));<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> doc2 = <span style="color: blue;">new</span> System.Xml.XPath.<span style="color: #2b91af;">XPathDocument</span>(filename);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> System.Web.<span style="color: #2b91af;">HttpContext</span>.Current.Cache.Insert(key, doc2, <span style="color: blue;">new</span> System.Web.Caching.<span style="color: #2b91af;">CacheDependency</span>(filename), <span style="color: #2b91af;">DateTime</span>.Now.AddMinutes(60), <span style="color: #2b91af;">TimeSpan</span>.Zero);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">navigator = doc2.CreateNavigator();</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">if</span> (type == <span style="color: #a31515;">&#8220;js&#8221;</span>)</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">iterator = navigator.Select(<span style="color: #a31515;">&#8220;/scripts/page[@pagecode='"</span> + pagecode + <span style="color: #a31515;">"']/script&#8221;</span>);</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> iterator = navigator.Select(<span style="color: #a31515;">&#8220;/styles/page[@pagecode='"</span> + pagecode + <span style="color: #a31515;">"']/style&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">while</span> (iterator.MoveNext())<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> scripts.Add(iterator.Current.InnerXml);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">return</span> scripts.ToArray();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">private</span><span style="color: blue;"> </span><span style="color: blue;">string</span> GetCacheKey(<span style="color: blue;">string</span> type, <span style="color: blue;">string</span> setName, <span style="color: blue;">string</span> version, <span style="color: blue;">bool</span> cancompress)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">return</span><span style="color: blue;"> </span><span style="color: #a31515;">&#8220;HttpCombiner.&#8221;</span> + setName + <span style="color: #a31515;">&#8220;.&#8221;</span> + type + <span style="color: #a31515;">&#8220;.&#8221;</span> + version + <span style="color: #a31515;">&#8220;.&#8221;</span> + cancompress;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">private</span><span style="color: blue;"> </span><span style="color: blue;">void</span> WriteBytes(<span style="color: blue;">byte</span>[] bytes, <span style="color: blue;">bool</span> isCompressed, <span style="color: blue;">string</span> type)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: #2b91af;">HttpResponse</span> response = context.Response;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.AppendHeader(<span style="color: #a31515;">&#8220;Content-Length&#8221;</span>, bytes.Length.ToString());<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (type == <span style="color: #a31515;">&#8220;js&#8221;</span>)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.ContentType = <span style="color: #a31515;">&#8220;application/x-javascript&#8221;</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.ContentType = <span style="color: #a31515;">&#8220;text/css&#8221;</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (isCompressed)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.AppendHeader(<span style="color: #a31515;">&#8220;Content-Encoding&#8221;</span>, <span style="color: #a31515;">&#8220;gzip&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.AppendHeader(<span style="color: #a31515;">&#8220;Content-Encoding&#8221;</span>, <span style="color: #a31515;">&#8220;utf-8&#8243;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> context.Response.Cache.SetCacheability(<span style="color: #2b91af;">HttpCacheability</span>.Public);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> context.Response.Cache.SetExpires(<span style="color: #2b91af;">DateTime</span>.Now.Add(CACHE_DURATION));<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> context.Response.Cache.SetMaxAge(CACHE_DURATION);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.ContentEncoding = <span style="color: #2b91af;">Encoding</span>.Unicode;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.OutputStream.Write(bytes, 0, bytes.Length);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.Flush();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">public</span><span style="color: blue;"> </span><span style="color: blue;">static</span><br />
<span style="color: blue;">string</span> GetScriptTag(<span style="color: blue;">string</span> setname, <span style="color: blue;">string</span> pageid, <span style="color: blue;">string</span> type, <span style="color: blue;">string</span> ver)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">string</span> result = <span style="color: #a31515;">&#8220;&#8221;</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (type == <span style="color: #a31515;">&#8220;js&#8221;</span>)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> result += <span style="color: #2b91af;">String</span>.Format(<span style="color: #a31515;">&#8220;&lt;script type=\&#8221;text/javascript\&#8221; src=\&#8221;/&#8221;</span> + Web.Utility.Functions.GetURLPrefix() + <span style="color: #a31515;">&#8220;ScriptCombiner.axd?s={0}&amp;v={1}&amp;type=js&amp;pcode={2}\&#8221;&gt;&lt;/script&gt;&#8221;</span>, setname, ver, pageid);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> result += <span style="color: #2b91af;">String</span>.Format(<span style="color: #a31515;">&#8220;&lt;link link href=\&#8221;ScriptCombiner.axd?s={0}&amp;v={1}&amp;type=css&amp;pcode={2}\&#8221; rel=\&#8221;stylesheet\&#8221; type=\&#8221;text/css\&#8221;/&gt;&#8221;</span>, setname, ver, pageid);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">return</span> result;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">public</span><span style="color: blue;"> </span><span style="color: blue;">static</span><span style="color: blue;"> </span><span style="color: blue;">string</span> CompressCSS(<span style="color: blue;">string</span> body)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = <span style="color: #2b91af;">Regex</span>.Replace(body, <span style="color: #a31515;">&#8220;/\\*.+?\\*/&#8221;</span>, <span style="color: #a31515;">&#8220;&#8221;</span>, <span style="color: #2b91af;">RegexOptions</span>.Singleline);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8221;  &#8220;</span>, <span style="color: blue;">string</span>.Empty);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #2b91af;">Environment</span>.NewLine + <span style="color: #2b91af;">Environment</span>.NewLine + <span style="color: #2b91af;">Environment</span>.NewLine, <span style="color: blue;">string</span>.Empty);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #2b91af;">Environment</span>.NewLine + <span style="color: #2b91af;">Environment</span>.NewLine, <span style="color: #2b91af;">Environment</span>.NewLine);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #2b91af;">Environment</span>.NewLine, <span style="color: blue;">string</span>.Empty);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8220;\\t&#8221;</span>, <span style="color: blue;">string</span>.Empty);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8221; {&#8220;</span>, <span style="color: #a31515;">&#8220;{&#8220;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8221; :&#8221;</span>, <span style="color: #a31515;">&#8220;:&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8220;: &#8220;</span>, <span style="color: #a31515;">&#8220;:&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8220;, &#8220;</span>, <span style="color: #a31515;">&#8220;,&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8220;; &#8220;</span>, <span style="color: #a31515;">&#8220;;&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8220;;}&#8221;</span>, <span style="color: #a31515;">&#8220;}&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = <span style="color: #2b91af;">Regex</span>.Replace(body, <span style="color: #a31515;">&#8220;/\\*[^\\*]*\\*+([^/\\*]*\\*+)*/&#8221;</span>, <span style="color: #a31515;">&#8220;$1&#8243;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = <span style="color: #2b91af;">Regex</span>.Replace(body, <span style="color: #a31515;">&#8220;(?&lt;=[&gt;])\\s{2,}(?=[&lt;])|(?&lt;=[&gt;])\\s{2,}(?=&amp;nbsp;)|(?&lt;=&amp;ndsp;)\\s{2,}(?=[&lt;])&#8221;</span>, <span style="color: blue;">string</span>.Empty);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">return</span> body;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p>You are now almost done with 50% of work for your project.</p>
<p>Now let&#8217;s take a look at the few of important execution steps that are in this function.</p>
<p>First of all we are declaring four different string variables:</p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">string</span> xStrType, xStrSet, xStrVer, xStrpagecode;<br />
</span></p>
<p>They will be used to get the Querystring passed in to this handler. This is utilized later on the code.</p>
<p>Moving next, you will find these function call:</p>
<p><span style="color: green; font-family: Courier New; font-size: 10pt;">//first check if client browser can support compressions<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> xBlnCanCompress = CanClientGZip(request);<br />
</span></p>
<p>This is basically to check does client browser support GZip compression.</p>
<p>Gzip compression, otherwise known as content encoding, is a publicly defined way to compress textual content transferred from web servers to browsers. HTTP compression uses public domain compression algorithms, like gzip and compress, to compress XHTML, JavaScript, CSS, and other text files at the server. This standards-based method of delivering compressed content is built into HTTP 1.1, and most modern browsers that support HTTP 1.1 support ZLIB inflation of deflated documents. In other words, they can decompress compressed files automatically, which saves time and bandwidth.</p>
<p>In the next step it is preparing the <em>stream</em> object used to hold the response output. We will not take dipper look into that code. As I expect that the a beginning developer even must be able know about next few line of code. <span style="font-family: Wingdings;">J</span></p>
<p>Let&#8217;s move to the line of code:</p>
<p><span style="color: green; font-family: Courier New; font-size: 10pt;">//now its time to read all the script/css files into a StringBuilder object.<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><br />
<span style="color: #2b91af;">StringBuilder</span> combinedSource = <span style="color: blue;">new</span><br />
<span style="color: #2b91af;">StringBuilder</span>();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">foreach</span> (<span style="color: blue;">string</span> file <span style="color: blue;">in</span> GetFileNames(xStrSet, xStrpagecode, xStrType))<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> combinedSource.Append(System.IO.<span style="color: #2b91af;">File</span>.ReadAllText(context.Server.MapPath(file), <span style="color: #2b91af;">Encoding</span>.UTF8));<br />
</span></p>
<p>As you can see in the foreach loop, it is calling to method <span style="font-family: Courier New; font-size: 10pt;">GetFileNames, </span>by passing 3 different parameters. Here this is also core and important part of this project. Let me outline you first what this function basically do. This function will read to the &#8220;script.xml&#8221; file that hold content of script file that we want to load. Please look inside the attached project solution to understand it better. The function will read xml file and return array of string object containing JavaScript files to read.</p>
<p>In the subsequent line of code, it iterate through each file name and read it. Each content of read file is placed inside a <span style="color: #2b91af; font-family: Courier New; font-size: 10pt;">StringBuilder </span>object.</p>
<p>Please take look at the code inside the <span style="font-family: Courier New; font-size: 10pt;">GetFileNames </span>function to understand what is actually happening inside it. It fetches the JavaScript/CSS based on the parameter passed. And return either the JavaScript file name array or CSS file name array.</p>
<p>So now we have a combined script/CSS with us. It&#8217;s a time to minify JavaScript/CSS now.</p>
<p>Following line of code will minify respective JavaScript/CSS based on type of client script requested.</p>
<p><span style="color: green; font-family: Courier New; font-size: 10pt;">//use the YUI Javascript/CSS minifier to compress all js files<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><br />
<span style="color: blue;">if</span> (xStrType == <span style="color: #a31515;">&#8220;js&#8221;</span>)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: #2b91af;">JavaScriptMinifier</span> minifier = <span style="color: blue;">new</span><br />
<span style="color: #2b91af;">JavaScriptMinifier</span>();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> minified = minifier.Minify(combinedSource.ToString());<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> minified = CompressCSS(combinedSource.ToString());<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p>The <span style="color: #2b91af; font-family: Courier New; font-size: 10pt;">JavaScriptMinifier </span>has been created in the 2<sup>nd</sup> step. Please refer to the attached solution project for more detail regarding this class file. I have adopted this class file from one of the article</p>
<p>You will also see function <span style="font-family: Courier New; font-size: 10pt;">CompressCSS </span>that is used to compress CSS file. The compressor of CSS file is done through just few regular expression. JavaScript compression has different algorithm.</p>
<p>After that it is calling to <span style="font-family: Courier New; font-size: 10pt;">WriteBytes </span>function that will prepare the combined &amp; compressed JavaScript &amp; CSS response and send it to the client.</p>
<p>Hurray… as part of implementation we are done.</p>
<p>Now it&#8217;s time to check that in action. You can run the project attached here with and check it In live action.</p>
<p>To download complete project, <a href="http://www.esnips.com/doc/bb247398-9971-4fac-bb8e-02a8e8ebad7d/JS-CSS-Combiner-Minifier">click here</a></p>
<p>Let&#8217;s compare the result of two different pages. The first one is with the compressed JavaScript &amp; CSS. The second one is with the normal JavaScript &amp; CSS. We will also see the difference in load time and size of content received.</p>
<p>Response time with compressed JavaScript &amp; CSS.</p>
<p><img src="http://techinsight.dhanashree.com/article-images/040510_1059_CombineComp1.jpg" alt="" /></p>
<p>Response time without compressed JavaScript &amp; CSS.</p>
<p><img src="http://techinsight.dhanashree.com/article-images/040510_1059_CombineComp2.jpg" alt="" /></p>
<p>As you can see from given statistics</p>
<p>With Combined &amp; Compressed JavaScript and CSS ..</p>
<p>Total request: 3</p>
<p>Response size: 16.3 KB</p>
<p>Without Combined &amp; Compressed JavaScript and CSS ..</p>
<p>Total request: 5</p>
<p>Response size: 96 KB</p>
<p>You can clearly see the difference between these two request.</p>
<p>To get more idea open and run the project yourself. That will give you better idea.</p>
<p>Hope you will find it very useful.</p>
<p>Happy coding…. <span style="font-family: Wingdings;">J</span></p>
<p><span style="font-family: Calibri; font-size: 15px; color: #ff0000;">NOTE<span style="mso-spacerun: yes;"> </span>:</span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="color: red;" lang="EN-IN"><span style="font-size: 11pt;"><br />
<span style="font-family: Calibri;">NOTE<span style="mso-spacerun: yes;"> </span>: Also visit <a href="http://www.dhanashree.com">www.dhanashree.com</a></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;"><br />
If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><br />
<a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;"><br />
Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/combinecompressminify-javascript-css-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>Implementing JQuery Model Popup Plug-In and Playing FLV file in a model popup</title>
		<link>http://techinsight.dhanashree.com/implementing-j-query-model-popup-plug-in-and-playing-flv-file-in-a-model-popup/</link>
		<comments>http://techinsight.dhanashree.com/implementing-j-query-model-popup-plug-in-and-playing-flv-file-in-a-model-popup/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 12:48:26 +0000</pubDate>
		<dc:creator>kiran</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[J-Query]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Developement]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://techinsight.dhanashree.com/implementing-j-query-model-popup-plug-in-and-playing-flv-file-in-a-model-popup/</guid>
		<description><![CDATA[Implementing J-Query Model popup Plug In

As shown in above screen, developing Model Popup will require 2 layers:

Disabled Back ground
Popup content Panel

We will implement a plug In and call it on Popup Panel element.
Somewhat like:  $(&#8220;div.popupDiv&#8221;).ShowPopup();

ShowPopup();
Is a plug-In method which will initiate an instance of the plug-In which we going to implement as next step.
Prior [...]]]></description>
			<content:encoded><![CDATA[<h1><span style="font-size: 13px;"><em>Implementing J-Query Model popup Plug In</em></span></h1>
<p><img src="http://techinsight.dhanashree.com/article-images/032410_1247_Implementin1.png" alt="" /></p>
<p>As shown in above screen, developing Model Popup will require 2 layers:</p>
<ol>
<li>Disabled Back ground</li>
<li>Popup content Panel</li>
</ol>
<p>We will implement a plug In and call it on Popup Panel element.</p>
<p>Somewhat like:  <span style="font-family: Courier New; font-size: 10pt;">$(<span style="color: #a31515;">&#8220;div.popupDiv&#8221;</span>).ShowPopup();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><strong><em>ShowPopup();</em></strong><br />
</span>Is a plug-In method which will initiate an instance of the plug-In which we going to implement as next step.</p>
<p>Prior to that a CSS for Disabled background needs to be developed</p>
<p>Which we can achieve as below:</p>
<p><span style="color: #a31515; font-family: Courier New; font-size: 10pt;">.popupbackGround<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">{<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">position</span>: <span style="color: blue;">absolute</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">height</span>: <span style="color: blue;">100%</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">width</span>: <span style="color: blue;">100%</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">left</span>: <span style="color: blue;">0px</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">top</span>: <span style="color: blue;">0px</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">background-color</span>: <span style="color: blue;">#000</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">z-index</span>: <span style="color: blue;">1</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">opacity</span>: <span style="color: blue;">0.5</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">filter</span>: <span style="color: blue;">alpha(opacity =50)</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">display</span>: <span style="color: blue;">none</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">}<br />
</span></p>
<p><span style="color: gray;"><em>We don&#8217;t have to assign this CSS class anywhere in HTML, but we will use this class while implementing Plug-In.</em><br />
</span></p>
<p><span style="color: gray;">Next to this, we will implement Model Popup J-Query Plug-In.<br />
</span></p>
<p><span style="color: gray;">Parameter to be passed to Plug-In: </span><span style="color: green; font-family: Courier New; font-size: 10pt;"><strong>closeButtonCSS<br />
</strong></span></p>
<p><span style="color: gray;">The plug in will be called on the popup panel itself and take one parameter called <strong>CloseButtonCSS </strong>which will be used to close the Model popup.<br />
</span></p>
<p><span style="color: gray;">We will create close event on the specified close button in parameter.<br />
</span></p>
<p><strong>model-popup.js<span style="color: gray;"> (Plug-In file)<br />
</span></strong></p>
<p><span style="font-family: Courier New; font-size: 10pt;">jQuery.noConflict();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">(<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">function</span>($K){<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">$K.fn.ShowPopup=<span style="color: blue;">function</span>(data)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">/*<br />
</span></span></p>
<p><span style="color: green; font-family: Courier New; font-size: 10pt;"> Parameters:<br />
</span></p>
<p><span style="color: green; font-family: Courier New; font-size: 10pt;"> closeButtonCSS,<br />
</span></p>
<p><span style="color: green; font-family: Courier New; font-size: 10pt;"> */<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> $K(<span style="color: blue;">this</span>).each(<span style="color: blue;">function</span>(i)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">var</span> dbBack,intTopAxis=0;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">var</span> objCloseButton= $K(<span style="color: #a31515;">&#8220;.&#8221;</span> + data.closeButtonCSS);</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">var</span> objPopup= $K(<span style="color: blue;">this</span>);</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">var</span> a;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">objCloseButton.click(<span style="color: blue;">function</span>(){</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> HidePopup();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> });<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> $K(window).scroll(<span style="color: blue;">function</span>()<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">var</span> xTop= parseInt($K(window).scrollTop()) + intTopAxis ;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> objPopup.animate({top:xTop+ <span style="color: #a31515;">&#8220;px&#8221;</span>},{queue: <span style="color: blue;">false</span>, duration: 350});<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> });<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> initBackGround = <span style="color: blue;">function</span>()<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> dbBack  = $K(<span style="color: #a31515;">&#8220;&lt;div&gt;&lt;/div&gt;&#8221;</span>).attr(<span style="color: #a31515;">&#8220;class&#8221;</span>,<span style="color: #a31515;">&#8220;popupbackGround&#8221;</span>).css(<span style="color: #a31515;">&#8220;height&#8221;</span>,$K(document).height()).hide();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> $K(<span style="color: #a31515;">&#8220;body&#8221;</span>).append(dbBack);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> intTopAxis= parseInt(($K(window).height())/2)-(objPopup.height()/2);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> ShowPopup = <span style="color: blue;">function</span>()<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> initBackGround();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> dbBack.fadeIn(<span style="color: blue;">function</span>(){objPopup.show();});<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> objPopup.css({<span style="color: #a31515;">&#8220;left&#8221;</span>: (($K(window).width())/2)-(objPopup.width()/2),<span style="color: #a31515;">&#8220;top&#8221;</span>: (($K(window).height())/2)-(objPopup.height()/2)+parseInt($K(window).scrollTop())}) ;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> HidePopup = <span style="color: blue;">function</span>()<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> objPopup.fadeOut();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> dbBack.fadeOut();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> ShowPopup();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> });<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">})(jQuery);</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><br />
</span></p>
<h1><span style="font-size: 13px;"><em>How to call Model Popup</em></span></h1>
<h1><span style="font-weight: normal; font-size: 13px;">Popup Plug-In can be called on any Div object. And the DIV itself will get displayed as a popup like shown in the above screen.</span></h1>
<p>For example:</p>
<p>Target popup DIV class is <span style="color: #a31515; font-family: Courier New; font-size: 10pt;">popupDiv.<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><br />
<span style="color: blue;">&lt;</span><span style="color: #a31515;">div</span><span style="color: #a31515;"> </span><span style="color: red;">class</span><span style="color: blue;">=&#8221;popupDiv&#8221;&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: #a31515;">div</span><span style="color: blue;">&gt;<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;"> </span> Popup Content Goes Here..</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">div</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: #a31515;">div</span><span style="color: #a31515;"> </span><span style="color: red;">class</span><span style="color: blue;">=&#8221;close&#8221;&gt;<span style="color: #000000;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">a <span style="color: #000000;"><span style="color: red;">class</span><span style="color: blue;">=&#8221;lnkClose&#8221;&gt;<span style="color: #000000;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">img <span style="color: #000000;"><span style="color: red;">src</span><span style="color: blue;">=&#8221;resource/small-closelabel.gif&#8221; <span style="color: #000000;"><span style="color: blue;">/&gt;&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></span></span></span></span></span></span></span></span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">div</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">div</span><span style="color: blue;">&gt;<br />
</span></span></p>
<p>We can popup by placing the following javascript :</p>
<p><span style="font-family: Courier New; font-size: 10pt;"> $k(<span style="color: #a31515;">&#8220;div.popupDiv&#8221;</span>).ShowPopup(<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> closeButtonCSS:<span style="color: #a31515;">&#8220;lnkClose&#8221;<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> });<br />
</span></p>
<p>Here &#8220;<span style="font-family: Courier New; font-size: 10pt;"><strong>closeButtonCSS:<span style="color: #a31515;">&#8220;lnkClose&#8221; </span></strong></span> is used to treat <strong>lnkClose </strong>as close button of popup.</p>
<h1></h1>
<h1><span style="font-size: 13px;"><em>Playing FLV</em></span></h1>
<p>To play any FLV file in HTML will require a flash based FLV player. There are many FLV players available among of those we will use one, which is a flash file and we can play FVL using the flash FLV player.</p>
<p>Here we will require 2 flash (SWF) files:</p>
<ol style="margin-left: 72pt;">
<li>flvplayer.swf (<a href="http://2gjqqg.bay.livefilestore.com/y1p79qAzBvUgYqQtUPobIBUzQlAhWgykS5T2dZdugTJteJPjhhsdFgkAa_B5ct_qVqgK8pBYFuwUhYeAc62aw4ycNoyv7gt2hce/flvplayer.swf?download">download </a>)</li>
<li>SteelExternalAll.swf (needs to be placed on same path of container HTML page) (<a href="http://2gjqqg.bay.livefilestore.com/y1pw8tb94dM-ToD4wwDeGTsH5473I2rvajjlhNetdx1lnAVF2smHXqBO17mTkfnOKhU-IPUg4PhoNtc-vcPe9cg9PbPC5V1HQwu/SteelExternalAll.swf?download">Download</a>)</li>
</ol>
<p>Below is how to embed object in HTML page to play FLV using above FLV player.</p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">object</span><span style="color: #a31515;"> </span><span style="color: red;">id</span><span style="color: blue;">=&#8221;Object1&#8243;</span><span style="color: blue;"> </span><span style="color: red;">height</span><span style="color: blue;">=&#8221;380&#8243;</span><span style="color: blue;"> </span><span style="color: red;">width</span><span style="color: blue;">=&#8221;400&#8243;</span><span style="color: blue;"> </span><span style="color: red;">classid</span><span style="color: blue;">=&#8221;clsid:D27CDB6E-AE6D-11cf-96B8- 444553540000&#8243; <span style="color: #000000;"><span style="color: red;">codebase</span><span style="color: blue;">=&#8221;http://macromedia.com/cabs/swflash.cab#version=6,0,0,0&#8243;&gt;</span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;"><span style="color: #000000;"><span style="color: blue;"><span style="color: #000000;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">param <span style="color: #000000;"><span style="color: red;">name</span><span style="color: blue;">=&#8221;movie&#8221; <span style="color: #000000;"><span style="color: red;">value</span><span style="color: blue;">=&#8221;flash/flvplayer.swf&#8221; /&gt;</span></span></span></span></span></span></span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: #a31515;">param</span><span style="color: #a31515;"> </span><span style="color: red;">name</span><span style="color: blue;">=&#8221;FlashVars&#8221;</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=&#8221;flvurl=../flash/test.flv&#8221;</span><span style="color: blue;"> </span><span style="color: blue;">/&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: #a31515;">param</span><span style="color: #a31515;"> </span><span style="color: red;">name</span><span style="color: blue;">=&#8221;quality&#8221;</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=&#8221;high&#8221;</span><span style="color: blue;"> </span><span style="color: blue;">/&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: #a31515;">param</span><span style="color: #a31515;"> </span><span style="color: red;">value</span><span style="color: blue;">=&#8221;true&#8221;</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=&#8221;autoplay&#8221;</span><span style="color: blue;"> </span><span style="color: blue;">/&gt;<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">embed</span><span style="color: #a31515;"> </span><span style="color: red;">height</span><span style="color: blue;">=&#8221;380&#8243;</span><span style="color: blue;"> </span><span style="color: red;">width</span><span style="color: blue;">=&#8221;400&#8243;</span><span style="color: blue;"> </span><span style="color: red;">src</span><span style="color: blue;">=&#8221;flash/flvplayer.swf&#8221;</span><span style="color: blue;"> </span><span style="color: red;">flashvars</span><span style="color: blue;">=&#8221;flvurl=../flash/test.flv&#8221; <span style="color: #000000;"><span style="color: red;">type</span><span style="color: blue;">=&#8221;application/x-shockwave-flash&#8221; /&gt;</span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">object</span><span style="color: blue;">&gt;<br />
</span></span></p>
<p>Above code will take FLV file path as a parameter, that is been specified at 2 places.</p>
<ol>
<li><span style="font-family: Courier New; font-size: 10pt;"><span style="color: red;">flashvars</span><span style="color: blue;">=&#8221;flvurl=../flash/test.flv&#8221;</span></span></li>
<li><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">param</span><span style="color: #a31515;"> </span><span style="color: red;">name</span><span style="color: blue;">=&#8221;movie&#8221;</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=&#8221;flash/flvplayer.swf&#8221;</span><span style="color: blue;"> </span><span style="color: blue;">/&gt;<br />
</span></span></li>
</ol>
<p>Your FLV file path will go here.</p>
<h1></h1>
<h1><span style="font-weight: normal; font-size: 13px;"><strong><em>Putting all together</em></strong></span></h1>
<p>Now we got both things ready with us.</p>
<ol style="margin-left: 72pt;">
<li>Implemented J-Query plug-In for model popup</li>
<li>FLV player</li>
</ol>
<p>Simply placing the &lt;object&gt; tag inside the Popup Div will result in our targeted output.</p>
<p>In addition to that we will require a Button to be clicked to show model popup. Like shown below</p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">a</span><span style="color: #a31515;"> </span><span style="color: red;">class</span><span style="color: blue;">=&#8221;lnkPopup&#8221;&gt;</span>Play FLV in Popup<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;<br />
</span></span></p>
<p>Let&#8217;s create a simple J-Query click event of the above link and call popup plug-In inside click event, like shown below.</p>
<p><span style="font-family: Courier New; font-size: 10pt;"><br />
<span style="color: blue;">&lt;</span><span style="color: #a31515;">script</span><span style="color: #a31515;"> </span><span style="color: red;">type</span><span style="color: blue;">=&#8221;text/javascript&#8221;</span><span style="color: blue;"> </span><span style="color: red;">language</span><span style="color: blue;">=&#8221;javascript&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><br />
<span style="color: blue;">var</span> $k=jQuery.noConflict();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> $k(document).ready(<span style="color: blue;">function</span>()<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> $k(<span style="color: #a31515;">&#8220;a.lnkPopup&#8221;</span>).click(<span style="color: blue;">function</span>()<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> $k(<span style="color: #a31515;">&#8220;div.popupDiv&#8221;</span>).ShowPopup(<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> closeButtonCSS:<span style="color: #a31515;">&#8220;lnkClose&#8221;<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> });<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> });<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> });</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">script</span><span style="color: blue;">&gt;<br />
</span></span></p>
<p>You can also download full source code ZIP file by clicking <a href="http://cid-180d3957230b5ca6.skydrive.live.com/self.aspx/Blog%20files/Popup%20FLV%20play/FLVplay-jq-modelpopup.rar">here</a> .</p>
<p><span style="font-family: Calibri; font-size: 15px; color: #ff0000;">NOTE<span style="mso-spacerun: yes;"> </span>:</span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/implementing-j-query-model-popup-plug-in-and-playing-flv-file-in-a-model-popup/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Utilizing CSS3 features: Creating interactive and optimized HTML form using CSS3 selectors</title>
		<link>http://techinsight.dhanashree.com/utilizing-css3-features-creating-interactive-and-optimized-html-form-using-css3-selectors/</link>
		<comments>http://techinsight.dhanashree.com/utilizing-css3-features-creating-interactive-and-optimized-html-form-using-css3-selectors/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 04:58:34 +0000</pubDate>
		<dc:creator>kiran</dc:creator>
				<category><![CDATA[CSS 3]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Web Developement]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://techinsight.dhanashree.com/utilizing-css3-features-creating-interactive-and-optimized-html-form-using-css3-selectors/</guid>
		<description><![CDATA[CSS3 gives a great flexibility to designers to create optimized HTML by utilizing CSS3 features.
CSS3 selectors gives rich amount of DOM element filtering, which will let designers to minimize inline attributes and inline styles in HTML code.
Here I am giving an overview of how to utilize CSS3 to develop an HTML form as shown below.

We [...]]]></description>
			<content:encoded><![CDATA[<p>CSS3 gives a great flexibility to designers to create optimized HTML by utilizing CSS3 features.</p>
<p>CSS3 selectors gives rich amount of DOM element filtering, which will let designers to minimize inline attributes and inline styles in HTML code.</p>
<p>Here I am giving an overview of how to utilize CSS3 to develop an HTML form as shown below.</p>
<p><img src="http://techinsight.dhanashree.com/article-images/030910_0457_UtilizingCS1.png" alt="" /></p>
<p>We will try to optimize HTML as much as possible by giving all styles and attributes through CSS3 in css file itself.</p>
<p><strong>Form Concept:<br />
</strong></p>
<p>As shown in below screen, we will be dividing form into 4 pieces,</p>
<ol>
<li>Header part (<span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">&lt;</span><span style="color: maroon;">th</span><span style="color: blue;">&gt;</span></span> )</li>
<li>Left side labels (<span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">&lt;</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span>)</li>
<li>Right side textbox area (<span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">&lt;</span><span style="color: maroon;">td</span><span style="color: blue;">&gt; &amp; &lt;</span><span style="color: maroon;">input</span><span style="color: maroon;"> </span><span style="color: red;">type</span><span style="color: blue;">=&#8221;text&#8221;</span><span style="color: blue;"> </span><span style="color: blue;">/&gt; </span></span> )</li>
<li>Bottom Buttons (  <span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">&lt;</span><span style="color: maroon;">input</span><span style="color: maroon;"> </span><span style="color: red;">type</span><span style="color: blue;">=&#8221;submit&#8221;/&gt;</span></span> )</li>
</ol>
<p><img src="http://techinsight.dhanashree.com/article-images/030910_0457_UtilizingCS2.png" alt="" /></p>
<p><strong>Generating Simple HTML form:<br />
</strong></p>
<p>As shown in below HTML, we will not give any attributes to TABLE or TD.</p>
<p>Just a simple Table with only one class which is assigned to TABLE, like <span style="font-family: Courier New; font-size: 10pt;"><span style="color: red;">class</span><span style="color: blue;">=&#8221;tblform&#8221;. </span></span>Very neat HTML without any kind of attributes assigned.</p>
<p><span style="text-decoration: underline;"><strong><em>HTML file code<span style="color: blue; font-family: Courier New; font-size: 10pt;"><br />
</span></em></strong></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">&lt;</span><span style="color: maroon;">table </span><span style="color: red;">class</span><span style="color: blue;">=&#8221;tblform&#8221;&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">th</span><span style="color: maroon;"> </span><span style="color: red;">colspan</span><span style="color: blue;">=&#8221;2&#8243;&gt;<span style="color: #000000;">Please enter your details below.<span style="color: blue;">&lt;/</span><span style="color: maroon;">th</span><span style="color: blue;">&gt;</span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;<span style="color: #000000;">Name<span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;<span style="color: #000000;"><span style="color: blue;">&lt;</span><span style="color: maroon;">input <span style="color: #000000;"><span style="color: red;">type</span><span style="color: blue;">=&#8221;text&#8221; /&gt;</span></span></span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;<span style="color: #000000;">Email<span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;<span style="color: #000000;"><span style="color: blue;">&lt;</span><span style="color: maroon;">input <span style="color: #000000;"><span style="color: red;">type</span><span style="color: blue;">=&#8221;text&#8221; /&gt;</span></span></span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;<span style="color: #000000;">Mobile<span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;<span style="color: #000000;"><span style="color: blue;">&lt;</span><span style="color: maroon;">input <span style="color: #000000;"><span style="color: red;">type</span><span style="color: blue;">=&#8221;text&#8221; /&gt;</span></span></span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;"><span style="color: #000000;"><span style="color: blue;">&lt;/</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;<span style="color: #000000;"><span style="color: blue;">&lt;</span><span style="color: maroon;">input <span style="color: #000000;"><span style="color: red;">type</span><span style="color: blue;">=&#8221;submit&#8221; <span style="color: #000000;"><span style="color: red;">value</span><span style="color: blue;">=&#8221;Submit&#8221; /&gt;<span style="color: #000000;"><span style="color: blue;">&lt;</span><span style="color: maroon;">input <span style="color: #000000;"><span style="color: red;">type</span><span style="color: blue;">=&#8221;submit&#8221; <span style="color: #000000;"><span style="color: red;">value</span><span style="color: blue;">=&#8221;Cancel&#8221; /&gt;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">&lt;/</span><span style="color: maroon;">table</span><span style="color: blue;">&gt;<br />
</span></span></p>
<p><strong>Developing CSS file:<br />
</strong></p>
<p>Once we got the above HTML ready, our all focus will be now on CSS to make it look like as shown in above screen shot,</p>
<p>In HTML there is only 1 CSS class assigned to TABLE which is <span style="color: blue; font-family: Courier New; font-size: 10pt;">tblform.<br />
</span></p>
<p>Further will be doing all stuffs in the CSS as given below,</p>
<p><span style="text-decoration: underline;"><strong><em>CSS file code<br />
</em></strong></span></p>
<p><span style="color: maroon; font-family: Courier New; font-size: 10pt;">.tblform<span style="color: #000000;">{</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">border-collapse</span>: <span style="color: blue;">collapse</span>;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: red;">width</span>: <span style="color: blue;">100%</span>;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">font-family</span>: <span style="color: blue;">Calibri</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">font-size</span>: <span style="color: blue;">11pt</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">}<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: maroon;">.tblform</span><span style="color: maroon;"> </span><span style="color: maroon;">td<span style="color: #000000;">{</span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: maroon;"><span style="color: #000000;"><span style="color: red;">padding</span>: <span style="color: blue;">5px</span>;</span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">border</span>: <span style="color: blue;">solid</span><span style="color: blue;"> </span><span style="color: blue;">1px</span><span style="color: blue;"> </span><span style="color: blue;">#E1E1E1</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">}<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: maroon;">.tblform</span><span style="color: maroon;"> </span><span style="color: maroon;">th<span style="color: #000000;">{</span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">padding</span>: <span style="color: blue;">5px</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">border</span>: <span style="color: blue;">solid</span><span style="color: blue;"> </span><span style="color: blue;">1px</span><span style="color: blue;"> </span><span style="color: blue;">#E1E1E1</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">font-weight</span>: <span style="color: blue;">normal</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">text-align</span>: <span style="color: blue;">left</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">background-color</span>: <span style="color: blue;">#E1E1E1</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">font-weight</span>: <span style="color: blue;">bold</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">}<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: maroon;">.tblform</span><span style="color: maroon;"> </span><span style="color: maroon;">td</span><span style="color: maroon;"> </span><span style="color: maroon;">input[type=text]<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">{<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">border</span>: <span style="color: blue;">1px</span><span style="color: blue;"> </span><span style="color: blue;">solid</span><span style="color: blue;"> </span><span style="color: blue;">#CCCCCC</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">width</span>: <span style="color: blue;">180px</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">height</span>: <span style="color: blue;">20px</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">padding-left</span>: <span style="color: blue;">5px</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">}<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: maroon;">.tblform</span><span style="color: maroon;"> </span><span style="color: maroon;">td:first-child<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">{<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">padding</span>: <span style="color: blue;">5px</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">border</span>: <span style="color: blue;">solid</span><span style="color: blue;"> </span><span style="color: blue;">1px</span><span style="color: blue;"> </span><span style="color: blue;">#E1E1E1</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">background-color</span>: <span style="color: blue;">#F2F2F2</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">}<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: maroon;">.tblform</span><span style="color: maroon;"> </span><span style="color: maroon;">td</span><span style="color: maroon;"> </span><span style="color: maroon;">input[type=submit]</span>, <span style="color: maroon;">.tblform</span><span style="color: maroon;"> </span><span style="color: maroon;">td</span><span style="color: maroon;"> </span><span style="color: maroon;">input[type=submit]:hover<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">{<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">background-image</span>: <span style="color: blue;">url(button-bg.gif)</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">background-repeat</span>: <span style="color: blue;">repeat-x</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">line-height</span>: <span style="color: blue;">22px</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">height</span>: <span style="color: blue;">25px</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">font-family</span>: <span style="color: blue;">Verdana,</span><span style="color: blue;"> </span><span style="color: blue;">Arial,</span><span style="color: blue;">Helvetica,</span><span style="color: blue;"> </span><span style="color: blue;">sans-serif</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">font-weight</span>: <span style="color: blue;">bold</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">font-size</span>: <span style="color: blue;">11px</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">color</span>: <span style="color: blue;">#333333</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">padding</span>: <span style="color: blue;">0px</span><span style="color: blue;"> </span><span style="color: blue;">10px</span><span style="color: blue;"> </span><span style="color: blue;">0px</span><span style="color: blue;"> </span><span style="color: blue;">10px</span>;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: red;">border</span>: <span style="color: blue;">1px solid <span style="color: #000000;"><span style="color: blue;">#999999</span>;</span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: red;">cursor</span>: <span style="color: blue;">pointer</span><span style="color: blue;"> </span><span style="color: blue;">!important</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">}<br />
</span></p>
<p>That&#8217;s it, it will result in a nice form with all CSS applied and HTML will remain neat as it is.</p>
<p><span style="font-family: Calibri; font-size: 15px; color: #ff0000;">NOTE<span style="mso-spacerun: yes;"> </span>:</span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/utilizing-css3-features-creating-interactive-and-optimized-html-form-using-css3-selectors/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

