This example was greatly inspired by the Stripes and jQuery AJAX Forms article from Freddy Daoud, but with some nice improvements
I’m working in a new Stripes/AJAX example.
The example 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 more…
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 more…
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.
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).
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 more…
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!
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).
Turn on compression
Apache uses mod_gzip to quickly and easily compress your files before you send them to the client. This speeds up your site like crazy!
If your hosting provider has mod_gzip module enabled, the best way to compress your content is to add the following lines to your .htaccess file:
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
unfortunately my provider doesn’t have this module enabled. If you have the same problem, you can add the following line instead:
php_value output_handler ob_gzhandler
this makes PHP to compress your PHP files.
To compress other static content I use Ali Farhadi’s JSmart Compressor which compress css and javascript files.
Setup JSmart
- Assuming your application resides in your web root, simply place the JSmart files into /jsmart.
- Edit /jsmart/config.php if you like, though the default settings should work fine. The mine looks like:
<?php
//JSmart Configuration File
//Show error messages if any error occurs (true or false)
define('JSMART_DEBUG_ENABLED', false);
//Encoding of your js and css files. (utf-8 or iso-8859-1)
define('JSMART_CHARSET', 'utf-8');
//Base dir for javascript files
define('JSMART_JS_DIR', '../');
//Base dir for css files
define('JSMART_CSS_DIR', '../');
//Change it to false only for debugging purposes
define('JSMART_CACHE_ENABLED', true);
//JSmart cache dir
define('JSMART_CACHE_DIR', 'cache/');
?>
- Create and chmod 777 /jsmart/cache
- Add the following lines into your .htaccess in your web root:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*\.(js|css))$ jsmart/load.php?file=$1
</IfModule>
Add future Expires and Cache-Control headers
A first-time visitor to your page will make several HTTP requests to download all your sites files, but using the Expires and Cache-Control headers you make those files cacheable. This avoids unnecessary HTTP requests on subsequent page views.
To set your Expires headers add these lines to your .htaccess:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
</IfModule>
and to set Cache-Control headers add:
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\\.(css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\\.(js)$">
Header set Cache-Control "max-age=216000, private"
</FilesMatch>
<FilesMatch "\\.(xml|txt)$">
Header set Cache-Control "max-age=216000, public, must-revalidate"
</FilesMatch>
<FilesMatch "\\.(html|htm|php)$">
Header set Cache-Control "max-age=1, private, must-revalidate"
</FilesMatch>
</IfModule>
Now all your files must have the right headers and be cacheable except the css and javascript files processed by JSmart. This is because JSmart overrides the cache headers when gzipping these files.
To fix this you have to edit /jsmart/load.php file and change the block code
if (JSMART_CACHE_ENABLED) {
if (isset($headers['If-Modified-Since']) && $headers['If-Modified-Since'] == $mtimestr)
header_exit('304 Not Modified');
header("Last-Modified: " . $mtimestr);
header("Cache-Control: must-revalidate", false);
} else header_nocache();
to
if (JSMART_CACHE_ENABLED) {
if (isset($headers['If-Modified-Since']) && $headers['If-Modified-Since'] == $mtimestr)
header_exit('304 Not Modified');
if ($file_type=='js') {
header("Expires: " . gmdate("D, d M Y H:i:s", $mtime + 216000) . " GMT");
header("Cache-Control: max-age=216000, private, must-revalidate", true);
} else {
header("Expires: " . gmdate("D, d M Y H:i:s", $mtime + 604800) . " GMT");
header("Cache-Control: max-age=604800, public, must-revalidate", true);
}
} else header_nocache();
Turn off ETags
By removing the ETag header, you disable caches and browsers from being able to validate files, so they are forced to rely on your Cache-Control and Expires header.
Entity tags (ETags) are a mechanism to check for a newer version of a cached file.
Add these lines to .htaccess:
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
Remove Last-Modified header
If you remove the Last-Modified and ETag header, you will totally eliminate If-Modified-Since and If-None-Match requests and their 304 Not Modified responses, so a file will stay cached without checking for updates until the Expires header indicates new content is available!
Add these lines to .htaccess:
<IfModule mod_headers.c>
Header unset Last-Modified
</IfModule>
Notes
With these settings you should have your site a lot faster and your file’s size greatly reduced.
Resources
Some descriptions are based on .htaccess (Hypertext Access) Articles from AskApache.
mod_gzip settings are taken from Highub - Web Development Blog.
Alongside with the IE6/IE7 Application Compatibility VPC Images (VPC Hard Disk Image for testing websites on IE on Windows XP SP2), Microsoft now provides an IE8 version.
This is a great way to test your web applications since the IE8 Beta1 installation overwrites the previous IEs present in your system.
I’m really impressed about Microsoft responding to their customers and to the community.
Microsoft Expands Support for Web Standards
Company outlines new approach to make standards-based rendering the default mode in Internet Explorer 8, will work with Web designers and content developers to help with standards behavior transition.
Microsoft’s Interoperability Principles and IE8
We’ve decided that IE8 will, by default, interpret web content in the most standards compliant way it can. This decision is a change from what we’ve posted previously.
Microsoft recently published a set of Interoperability Principles. Thinking about IE8’s behavior with these principles in mind, interpreting web content in the most standards compliant way possible is a better thing to do.
That’s awesome. An unified industry can move forward.
Microsoft has created Code Gallery.
Code Gallery is a place for projects sharing, created to demonstrate .NET key features with a primary focus on C#.