Jul 26

.htaccess – Gzip and Expires and a Cache-Control to your website site for faster loading

To speed up my site and save bandwidth, I use .htaccess file to gzip my text based files and optimize cache HTTP headers.

Turn on compression

mod_gzip is an external expansion method for Apache that allows you to quickly constrict your information before you send them to the users browsers.

If your in linex hosting and it has mod_gzip module enabled, the easy way to compress is to add the following code to your .htaccess file:

or, DEFLATE method

Add an Expires and a Cache-Control Header

Website designs are getting rich and fast, which means more scripts, CSS, images, and Flash in the site. A first-time visitor to your web page makes HTTP requests, but by using the Expires header you make those elements cacheable. This prevents unnecessary HTTP requests and Bandwidth. Expires headers are most often used with images, but they should be used on all elements including JS, CSS, and Flash elements.

To set your Expires headers add these lines to your .htaccess:

To set Cache-Control headers add these lines to your .htaccess:

If you can’t change your .htaccess file, you can use PHP to return compressed content. Give your HTML file a .php extension and add this code to the top

Turn off ETags

By removing the ETag, you disable caches and browsers from being able to validate information, so they are forced to depend on your Cache-Control and Comes to an end headlines.
Entity meta data (ETags) are a process to check for a modern edition of a cached file.

Add these lines to .htaccess:

Remove Last-Modified header

If you remove the Last-Modified and ETag, you will completely get rid of If-Modified-Since and If-None-Match needs and their 304 Not Customized responses, so a page file will remain cached without verifying for up-dates until the Comes to an end Expires header indicates new content is updated.

Add these lines to .htaccess:

Jul 26

Speeding Up Your Web Site and Reduce Loading Time

Simple Steps to Decrease Website Loading Time

Minimize HTTP Requests

Most of this time is taken for downloading all the components in the page : images, CSS, scripts, Flash, etc. Reducing the number of components to Reduce number of Requests in page.

Combined files

This is the a way to reduce the number of HTTP requests by combining all stylesheets, scripts

So this:

Becomes this:

Image maps

Combine multiple images into a single image. The overall size is about the same, but reducing the number of HTTP requests.

Use CSS Background Position:

Put Stylesheets at the Top

Placing stylesheets in the TOP allows the page to load progressively.Front-end developers care about performance and page want to load progressively, that is, we want the browser to display whatever content it has as soon as possible.In our case the HTML page is the progress indicator! When the browser loads the page progressively the header, the navigation bar, the logo at the top, etc. all serve as visual feedback for the user who is waiting for the page. This improves the overall user experience.In our case the HTML web page is the progress indicator! When the page loads progressively logo, than body elements from top to bottem. all are visual reviews for the users who is waiting for the site. This helps the overall user experience.The problem with placing CSS near the bottom of the page is that it discourages progressive loading in browsers. These browsers reduces progressive rendering and it to redraw elements of the page. The user is trapped looking at a empty white web page.Moving style sheets to the document HEAD element helps pages appear to load quicker since this allows pages to render progressively.

Put Scripts at the Bottom

The issue due to scripts is that they makes parallel download. That browsers download elements in parallel. If you provide your images from several hostnames, you can get more than two downloads available to happen in similar. While a script is loading, however, the browser won’t begin any other downloads available, even on different hostnames.In some circumstances it’s not simple to switch scripts to the end. If, for example, the script uses document.write to place aspect of the page’s content, it can’t be shifted lower in the site. There might also be scoping concerns. In many situations, there are tips on how to workaround these situations.An substitute recommendation that often comes up is to use postponed programs. The DEFER credit indicates that the program does not contain papers.write, and is an idea to surfers that they can proceed making. Unfortunately, Chrome doesn’t assistance the DEFER credit. In Online Internet explorer, the program may be postponed, but not as much as preferred. If a program can be postponed, it can also be shifted to the end of the site. That will make your websites fill more quickly.

Make JavaScript and CSS External

Should JavaScript and CSS be contained in external files is generally better.Using external files usually creates more quick loading because the JavaScript and CSS files are cached by the browser. JavaScript and CSS that are inlined in HTML files get downloadable every time the pages is loaded. This reduces the number of HTTP requests that are required, but improves the size of the HTML papers. On the other hand, if the JavaScript and CSS are in external cached by the browser.

Avoid Redirects
Types of Redirects:
  • 300 Multiple Choices (based on content-Type)
  • 301 Moved permanently
  • 302 Moved Temporarily
  • 303
  • 304 Not Modified
  • 305 Use Proxy
  • 306 (no longer used)

The browser automatically takes the user to the URL specified in the Location field. All the information necessary for a redirect is in the headers. The body of the response is typically empty. Despite their names, neither a 301 nor a 302 response is cached in practice unless additional headers, such as Expires or Cache-Control, indicate it should be.

There are other ways to automatically redirect users to a different URL. The meta refresh tag included in the head of an HTML document redirects the after the number of seconds specified in the content attribute:

JavaScript and Jquiry also used to perform redirects

Avoid Empty Image src
Preload Images

By preloading components you can take advantage of the time the browser is idle and request components (like images, styles and scripts) you’ll need in the future. This way when the user visits the next page, you could have most of the components already in the cache and your page will load much faster for the user.By preloading elements you can take benefits of reducing time of loading in browser. The preloaded files you will need in future. This way when the person trips the next web page, you could have most of the elements already in the storage cache and your web page will fill much more quickly for the person.

Preload Using CSS :

Preload Using Jquiry :

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

To speed up my site and save bandwidth, I use .htaccess file to gzip my text based files and optimize cache HTTP headers.

  • Turn on compression
  • Add an Expires and A Cache-Control Header
  • Turn off ETags
  • Remove Last-Modified header
Jul 26

How to avoid conflict between jquery and prototype

To avoid the conflict have 2 method

1.Use the noConflict for jquery, assign new variable for $, and Use the new variable wherever you would have used the $ for jQuery

2. If you don’t need to mix Prototype/jQuery you can wrap all of your jQuery code in an anonymous function. and can use where ever.

Jul 26

Responsive Web Design Tutorial

Responsive Web Design

Check your website with different devices
Responsive Web Design allows your websites to fit the screen, This is the time for smartphones and iPads, all browsing websites is not limited to standard computers. Now people are browsing websites through mobiles and their smartphones and tablets.
With the release of devices such as the iPad, and a recent increase in the reputation of browsing the web on your smartphone, 2012 is almost certainly going to see the creation of many more responsive web designs. By utilising this simple technique, it is possible to design a more compatible, more ergonomic website that will look great and function brilliantly on any device.

Check your website with different devices

Flexible grid

It is impossible to design with this approach without having a grid system, most websites were designed using a fixed width style and centered content but for Responsive grid you need to give the measurements in percent, not pixels. This means that a 50% width will always be half of the screen the website is shown on, regardless of its size.This is where flexible and responsive web design starts from. fixed width design is not the best solution for your designs and therefore liquid layouts are the new answer.

Calculation %=( 200px x 100 ) / 960
fluid grids can be beneficial for doing an precise resizing when going from one resolution to another, it can get a little difficult when you have grid column systems and you want to create them fit in a mobile phone display, luckily this issue has been settled with media queries, of which we’ll be see later.
The whole concept of responsive designs is creating websites and apps that are able to re-size to the perspective where they are currently being considered and provide an enhanced edition for that present particularly, this can also be designed through media queries, but first we want to talk about some other factors regarding responsive designs.

Fluid Images & Backgrounds

Better for backgrounds, use CSS background in-stand images in CSS3 have more features for background that are like gradient, positions, transitions, max-width, max-height, etc., Also you can use different size of images regrading screen Resolutions.

For Responsive Images you can use JavaScript or Jquery to change images as responsive with screens,

can change image source (src) by JavaScript or to use media query change the backgrounds by CSS styles itself.

The data-fullsrc is a custom HTML5 attribute, identified in the data files included on Github. Each time visitors visiting to site on a screen whose image resolution is greater than 480 px, the larger picture will load, while in smartphone and tablet, the small picture will load instantly.
when we using JavaScript to replace images, that will load after page elements are loaded, it will rewrite all codes from original code according to the current screen resolution, this technique can become a great bandwidth saver.

Media Queries for Responsive Websites

Media queries are takes a design from fluid to truly responsive. we can use media query is attribute of

style sheet, also CSS3 introduced the concept of using a query’s as styles from same embedded external style sheet.

Here the simple Query used in tag

Here Query CSS tag for full Media Query website like this,

Media queries allows cascading style sheets to check for the conditions of particular media features when utilized by a device. This allows for a just one style sheet to contain multiple styles and allow for responsive layouts.
Separate styles for multiple devices can be stored in just one single style sheet.
The demo for the responsive design….. just resize browser with this page
same style sheet Media queries like this,

With the release of devices such as the iPad, and a recent increase in the reputation of browsing the web on your mobile phone, 2012 is almost certainly going to see the creation of many more responsive web designs. By utilising this simple technique, it is possible to design a more compatible, more ergonomic website that will look great and function brilliantly on any device.
The prospective that media queries hold is tremendous, and with their help, web developers are now far better equipped for the future. If there was ever a good time to learn more on media queries and how to utilise them effectively, that time is now.
Check your website with different devices