samaxes

Icon

on technology

More on compressing and caching your site with .htaccess

.htaccess - gzip and cache your site for faster loading and bandwidth saving” is one of the most popular posts on samaxes.
It’s basically on how to compress and cache your site content with Apache and .htaccess file.

It works like a charm, but it’s not yet the perfect configuration for me.
I wanted something that I can use out-of-the-box without having to rely on external extension modules or tools.

If you are lucky enough to have Apache 2 with your hosting provider you can use the mod_deflate module that comes bundled with it.

In order to compress your text files with this Apache’s module you just have to add the following lines to your .htaccess file:

?View Code APACHE
1
2
3
4
5
<IfModule mod_deflate.c>
  <FilesMatch "\.(css|js|x?html?|php)$">
    SetOutputFilter DEFLATE
  </FilesMatch>
</IfModule>

This will gzip all your *.css, *.js, *.html, *.html, *.xhtml, and *.php files.
Read the rest of this entry »

Fresh Layout for 2009

With the new year starting, I decided to try some changes here at samaxes.com.

First, I’ve changed the blog theme to a slightly modified Derek Punsalan’s Grid Focus.
Some of these modifications were mostly due to some complains about the size of the content column versus the sidebars columns on the previous theme. Since this is mainly a technical blog it makes it easily on the eye to have a wider content column.

Another visual change was the code syntax highlighting plugin. I was using the SyntaxHighlighter Plus and now I’m using WP-CodeBox.
SyntaxHighlighter Plus served me well in the past, but it has some disadvantages, such as:

  • Escapes the code special characters, making it harder to edit code (also has a bug when escaping ‘&’ ampersand characters);
  • Require that a lot of JavaScript files are sent to the client in order to style the code.

Although I’m using browser caching, 70-80% of this blog visitors are new visitors, so the cache won’t help them. This means that I should try to minimize the number of HTTP requests as much as I can.
WP-CodeBox is based on the GeSHi syntax highlighter. All the parsing is executed on the server side and it supports a lot more languages than the SyntaxHighlighter.
Read the rest of this entry »

Stripes and jQuery Autocomplete

I really enjoy jQuery. But finding the right UI widget can be a daunting task.
Autocomplete is one of those widgets.

I decided to share an asynchronous example on how to use the jQuery Autocomplete plugin with Stripes.

Here’s an example output:
Stripes and jQuery Autocomplete example
Read the rest of this entry »

JBoss AS 5.0 is out!

JBoss announced the GA release of JBoss AS 5.0.

JBoss 5 is the next generation of the JBoss Application Server build on top of the new JBoss Microcontainer. The JBoss Microcontainer is a lightweight container for managing POJOs, their deployment, configuration and lifecycle. It is a standalone project that replaces the famous JBoss JMX Microkernel of the 3.x and 4.x JBoss series. The Microcontainer integrates nicely with the JBoss framework for Aspect Oriented Programming, JBoss AOP. Support for JMX in JBoss 5 remains strong and MBean services written against the old Microkernel are expected to work.

JBoss5 is designed around the advanced concept of a Virtual Deployment Framework (VDF), that takes the aspect oriented design of many of the earlier JBoss containers and applies it to the deployment layer. Aspectized Deployers operate in a chain over a Virtual File System (VFS), analyze deployments and produce metadata to be used by the JBoss Microcontainer, which in turn instantiates and wires together the various pieces of a deployment, controlling their lifecycle and dependencies.

See the full release notes and downloads page.

And good luck to get your J2EE applications working with this new version.

Stripes and jQuery: AJAX forms and HTTP Session Validation

This example was greatly inspired by the Stripes and jQuery AJAX Forms article from Freddy Daoud, but with some nice improvements

Last week I was working on a new Stripes/AJAX example. It involves having a table listing entities, being the last row of the table a form for adding new ones.
The form gets submitted via AJAX, using jQuery, and the response is validated in order to check if the HTTP session is still valid.

If everything is OK, the list is refreshed and a success message appears. On the other hand, if validation errors occur, the list is refreshed and an error message appears.
Also, if the user’s session has expired on the server, an alert is shown to inform the user that his session is invalid, and the page is reloaded so the user can login once more.
Read the rest of this entry »

The Semantic Web and RDFa

There is a lot of momentum around Semantic Web and RDFa.
This may be caused by the big milestone reached for RDFa, a Candidate Recommendation of RDFa in XHTML: Syntax and Processing.

Recently, several discussion threads have been started on the WHATWG mailing list around the effort of integrating RDFa into the HTML5 specification as XHTML1.1 and XHTML2 that will have it integrated.

While I was pretty aware of the Microformats activity, I can’t say the same about RDFa. But Manu Sporny makes it a lot easier. In fact, this is by far the most comprehensive explanation of RDFa that I have ever seen.
Read the rest of this entry »

samaxesJS JavaScript Controls

samaxesJS is a set of utilities and controls, written in JavaScript, for building rich interactive web applications.

The first extension is a dynamic Table of Contents script.

The TOC control dynamically builds a table of contents from the headings in a document and prepends legal-style section numbers to each of the headings:

  • adds numeration in front of all headings,
  • generates an HTML table of contents,
  • degrades gracefully if JavaScript is not available/enabled.

More information available in the project home page at Google Code Hosting.

BIRT/Stripes example

A long time has passed since my previous BIRT examples Deploying BIRT Report Engine API with Jakarta Struts and Deploying BIRT Report Engine API with Stripes.
Although they have received a lot of attention and downloads, the examples were really basic and are now outdated.

Since I had to use BIRT in my last projects I decided to update my BIRT/Stripes example.
This example doesn’t depend on the Tribix project anymore since BIRT supports HTML/Paginated HTML, PDF, Excel, Word, PowerPoint, and PostScript outputs (images/charts are not embedded in Excel output).

BIRT WebReport Example

I’ve tried to follow some good practices that I think are important to use in a production application:

  • There is a significant cost associated with creating an engine instance, due primarily to the cost of loading extensions. Therefore, each application should create just one ReportEngine instance and use it to run multiple reports. In this example the engine is started in the context listener and the same instance is always used.
  • All texts in the report should be loaded from the resources so the application can be fully localizable and fully internationalized.
  • You should use a JDBC data set to preview your report with BIRT designer but you must swap the data set in runtime to use data from your business logic.
  • You should use predefined styles instead of custom styles as much as you can.
  • Not a good practice but often a requirement, hide the master page when generating a HTML report, and change the visibility of elements so they are visible only to specified outputs.

For this example BIRT Runtime Engine 2.2.2 2.3.1, and Stripes Framework 1.5 were used.
Read the rest of this entry »

HTML 5 @media 2008

Now that almost everyone has heard about HTML 5, maybe not all of you know what’s new for us developers.

Lachlan Hunt and James Graham have presented on 2008-05-29 at @media 2008 in London Getting Your Hands Dirty with HTML5.
I really find it a great presentation and a good start if you want to check what’s new with the new HTML/XHTML version.

Lachlan Hunt is also the editor of The Web Developer’s Guide to HTML 5. Any suggestions can be added to the wiki.
We are all welcome to contribute, so let’s get our hands dirty!

.htaccess - gzip and cache your site for faster loading and bandwidth saving

Last week I changed my hosting provider from Site5 to NearlyFreeSpeech.NET.
Despite the fact that the first one is faster than the second, NFSN is a lot more cheaper (I only pay what I really use).

So in order to speed up my site and save bandwidth (the more I use the more I pay) I use .htaccess file to gzip my text based files and optimize cache HTTP headers.
Although this site is powered by Wordpress which has some really great plugins to optimize PHP output I wanted a more generic solution which can be applied to all PHP web applications.

I also try to follow as much as I can the rules for high performance web sites so don’t be surprised if some Expires header seems too long (far future Expires header rule requires at least 172801 seconds).
Read the rest of this entry »

About

samaxes is the personal site of Samuel Santos, a professional web developer living in Coimbra, Portugal. This site is a simple portal for information about technology and software development, focusing on Java technologies, Open Source and Web Standards.

Archives