Tag Archives: javascript

The Developers Conference 2011

From July 6 to 10 happened The Developers Conference 2011 down here in São Paulo. The other editions were really good and, better, this one topped all of them. It was a really fun and productive event. I had the chance to meet friends and to get to know new people. If you were not there, #protip for you: BE THERE NEXT YEAR. Really.

Before talking more about the conference, I have to thank Globalcode (in special Vinicius and Yara). They did a great job =)

Since last year, the premise of the conference is to have people from all kinds of backgrounds, from a lot of different communities, like Java, Ruby, Python, Agile, Javascript, .NET and lots more. Each day featured five different tracks, with different topics, to fit all those communities and tools. The result is that we had a lot of different people and lots of opportunities to talk to people you usually would not encounter. This was a really enriching experience.

In a personal level, this conference was special to me: I made two ‘speaking’ participations. In one of them I talked about Scala, an introductory talk (you can find the sample code used in the talk in my github). The other one was a panel consisting of people from different languages on the jvm – lots of fun =)

In the event, I had one personal fail moment, that should remain as a tip for everyone out there. In a given moment, when talking to someone, I was asked for my business card… and didn’t have any on me. So the obvious tip: always have business cards with you. Always.

Now, if you follow my posts about events you may have noticed that this one is a little different. It contains no pictures. This is due to a second fail, that happened on this last Monday. I lost (or it got stolen…) my mobile. And with it, all the pictures from the entire event. Sorry =(


The Snitcher

The Snitcher is a new Open Source project we just made available at Kenai. It comes to help us solving a problem that occurs a lot occurs a lot to us: allowing users to easily submit bug reports. It is still not feature complete, but it is already possible for users to report bugs through the tool.

The way it works is very simple. You just have to deploy the application in any java application server. For now, there is just two boring steps that need to be done. The domain variable in the snitcher-loader.js script file, and the URL for the css file and for the form action in the snitcher.jsp file must be set to the correct values.

Then you add a simple <script> tag in your page, as follows:

<script type="text/javascript"
    src="{domain}/Snitcher/snitcher-loader.js">
</script>

Here, {domain} is the domain under which the application was deployed. This will load a small script, which will load Snitcher itself the first time a page try to display it.

To display the reporting window, you can attach a javascript function loaded in the previous script called toggleSnitcherOpen(element) to any onclick event you want, where element is the place in the page you want to store Snitcher – you can use something as simple as body).

After loading, this is how Snitcher should look (as of now, it is likely to change in the future):

snitcher

snitcher

Now, there is still a lot of work to be done. If you are interested in helping out, or just on keeping an eye on how the project goes, visit the project site at kenai.com/projects/snitcher. Also, take a look at the wiki for where exactly we are looking for help right now.

Finally, please let us know in the comments, e-mails or in the discussion list if you have any comments!


Compressing JavaScript and CSS files with YUI Compressor

Performance is always something to be looking for when developing web applications. One possible approach to improve performance of such applications is to compress our JavaScript and CSS files. This will make them smaller and thus faster to download.

A JavaScript compressor could for example turn this:


function helloWorld() {

    alert("Hello World");

}

into something like this:


function helloWorld() {alert("Hello World");}

It gets unreadable, but smaller. When applied to several, potentially large files, this type of compression can help us save a lot of kbytes of download from the server to a client, thus making the page load faster.

Since this is a simple strategy, it’s tempting to write our small routine to apply this compression to our files; but such a trouble is not necessary. There are libraries out there do this for us. We will use the YUI Compressor, from Yahoo, here.

The usage pattern I like is to compress all JavaScript and CSS files right before packaging the application. You can do this manually, and the official YUI Compressor site has instructions on how to do it. But this way you will probably end up forgetting to do so. Since we already use Ant in our projects at IPTI, we also use Ant to automate this compression step.

The first step to use YUI inside Ant is to get the ant task jar file here. Put the jar file in Ant’s classpath and you are ready to continue. PS.: The last time I tried, the YUIAnt site was unreachable. If that is still case for you when you read this, please let me know and I can make the version I have available.

Now, inside your Ant file, declare the yuicompressor task. Something like this:

<taskdef name="yuicompress"
  classname="com.yahoo.platform.yui.compressor.YUICompressTask"
  classpathref="lib.path"/>

and then use it like this:

<target name="minify-js" description="minify the project's JS files">
  <echo message="minifying JS files" level="info"/>
  <yuicompress charset="UTF-8" outputfolder="distdir">
    <fileset dir="srcdir" includes="**/*.js"/>
  </yuicompress>
</target>

Replace all the js by css‘s and you are set for CSS files as well.

Now, you probably have an Ant target to build your application war file – let’s call it dist. Just put minify-js and minify-css (supposing you created this second one) in dist‘s depends attribute. Now, each time you build your application, its JavaScript and CSS files will get compressed!

The last problem is that it doesn’t make sense to do this compression during normal development. The files would be impossible to read and debug properly. The solution again is very simple: add a property to the ant file, that says whether the compression should be executed or not.

This should suffice:

<property name="minify.js" value="true"/>

and add this to the minify-js (and css) targets:

<target name="minify-js" if="minify.js"
    description="minify the project's JS files">

An important detail to notice is that, to disable the compression you must comment the property altogether. Changing its value from “true” to “false” will do no good – actually, the value can be anything, it just need to be there.


Follow

Get every new post delivered to your Inbox.