Here is a howto on calculating bond. I actually learned something new from this blog entry that wasn’t taught in the class or the text.
Archive for October, 2008
Calculating Bond
s.gif from extjs.com
Special thanks to Ari for pointed this blog to me on a cleaner way to change the s.gif link. I was tweaking the library source directly before.
Textfield scrollaway
Special thanks to FlexIDX for the suggestion on this thread. Before, the text fields on a form panel would separate when scrolling. After specified position:relative; on text fields’ style property fixed the scrolling issue. However, the cursor disappeared on FireFox 2.x. Fortunately, this new issue is isolated on Firefox 2.x only.
Minify using an ANT target
Manually minify files is doable when the files are not changed frequently and you do not have many files to minify. If you have JavaScripts that change frequently due to active development or have a large number of files, you might want to consider to automate it. One way to do so is to use ant target for YUI Compressor.
Here is the configuration that I used to setup the minify. You may wish to change directory/file location and file names to match your environment. You can also update the exclude list (i.e. excludes="/lib/**/**/*.js,**/other_special_file.js") for correct files that YUI Compressor can not handle.
<target name="-pre-dist">
<echo level="info" message="Compressing JavaScript and CSS files...." />
<available file="${basedir}/../libs/jars/YUIAnt.jar" property="YUIANT_AVAILABLE" />
<fail unless="YUIANT_AVAILABLE" message="Run jar target to generate the required task"/>
<path id="yuicompressor.classpath">
<fileset dir="${basedir}/../libs/jars">
<include name="yuicompressor-2.3.6.jar"/>
<include name="YUIAnt.jar"/>
</fileset>
</path>
<taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
<classpath>
<path refid="yuicompressor.classpath"/>
</classpath>
</taskdef>
<yuicompress linebreak="8000" warn="false" munge="no" preserveallsemicolons="true"
outputfolder="${basedir}/${build.web.dir}" >
<fileset dir="${basedir}/web" excludes="/lib/**/**/*.js,**/other_special_file.js" >
<include name="**/*.js" />
<include name="**/*.css" />
</fileset>
</yuicompress>
<echo level="info" message="Compression Complete" />
</target>
Enabling gzip HTTP Compression on Glassfish
I followed this blog to configure my instance of glassfish to enable gzip compression for HTTP traffic. Here is my version of the configuration:
<property name="compression" value="on"/> <property name="compressableMimeType" value="text/html,text/xml,text/plain,image/gif,image/jpeg,image/png,text/css,text/javascript,application/json"/>
After restarted the sever, I noticed that not all files were compressed. Some css files were compressed while some other css files didn’t. I wonder why?
Minifying a tagcloud widget
I was using an earlier built of this tagcloud widget. I wanted to minifying the widget. So, I started with using JSMin and found out that Prototype.js and window.js causes UnterminatedStringLiteralException with JSMin. So, I left these two files alone. Once I minified rest of the files, I cat the files into a single JavaScript. The net result was about 100k size reduction and a lot less number of connections for the browser.
Here is the cat command that I used:
cat libraries/prototype/prototype.js libraries/prototype/effects-min.js libraries/prototype/builder-min.js libraries/prototype/effects-min.js libraries/prototype/dragdrop-min.js libraries/prototype/controls-min.js libraries/prototype/slider-min.js libraries/prototype/scriptaculous-min.js libraries/prototype/window.js widgets/dialog/dialog-min.js widgets/tagCloud/tagcloud-min.js widgets/tagCloud/tagCloudDialog-min.js interface-json-min.js > tagcloud-all.js
An encoding workaround
For the last couple days, I’ve been tweaking URL encoding with UTF-8 characters using JavaScript. I got an interesting situation where when the hash part of the URL (i.e. “mystate_information” in this URL http://myserver/myapp.html#mystate_information) works fine when it’s being updated by the JavaScript or the state manager. When loading the URL directory from bookmark or in the address bar, the state sometimes would get decoded before reach my state handling code instead passing in raw string. This means that the state sometimes is encoded and sometimes isn’t. This makes coding a little challenging.
Here is a workaround that I figured out. Since URL encoded text has “%” characters, I look for this character. If it exists, do the decoding. If not, skip decoding. Here is a simple sample code:
var input = mystate_information;
if(input.indexOf('%') != -1)
input = aDecodeFunction(mystate_information)
Do you know of a corner case that this might not work? Or do you have a smarter idea?
