Minimize Your Javascript Source Code By YUI Compressor

Web application or web app is a ideal solution to implement a cross platform applicatoins. In a web app, we may use lots of JavaScript files. Especially when we want to design a great app with well formed structure, we may create one JavaScript file for each one Class. Hence, there may be over dozens of files in one web app. As we know that all browsers have a limitation of http simultaneous connection from a given domain and a limitation of total concurrent connection (Browser profiling). The connection includes downloading images, CSS files, JavaScripts, etc. It will take very long before user can start to use the app. There are two ways to reduce the loading time. One is reducing the file size. Another one is reducing the number of files to be downloaded.
Read more

Login With Remember Me By Session And Cookie

It is funny that I always forget that how “Remember Me” works but I just keep in mind how to implement it in PHP. I think it is very necessary for me to write it down so that I can check it from time to time, in case that I forget it again. In this post, I will explain how session works in the common way and I will show you what is the difference between login with remember me and login without remember me. All example code will write in PHP.

When you visit a website in the browser, the website may assign an unique id for you in order to save all your data with this unique id. Therefore, it can restore your data when you come back next time. The unique id is called session id.

Website uses session id to identify an unique visitor. At the first time you access the website, it will generate a session id and send it back to your browser. Normally, the session id will be stored in browser cookie if your browser cookie is enabled. (Usually, the cookie is enabled in all browsers.) To make it more clear, I write an example. The following code will record your visit times in session. Each time you visit this page, it will show your how many times you have visited.
Read more

HTTP Header Fields Howto

When we are browsing website, it always takes longer time to load the page in first time than that in second time. Sometimes it will take 5 seconds to download a file, but it may only take you 1 seconds for downloading the same file. It’s all because Browser cache and HTTP header fields. Cache mechanism is doing a good job to improve the HTTP service performance. By setting some cache fields in HTTP header, we can reduce the number of requests and save a lots of bandwidth as well. In the meantime, it will also improve the user experience with website by reducing the loading resource. Here is an common HTTP Response example:
Read more

Browser and Website HTTP Cache

Last-Modified and HTTP-IF-MODIFIED-SINCE is the most common cache mechanism between browsers and web server. Usually, when we access one static html page, web server will return us one 200 HTTP response with Last-Modified information. Our browsers will keep this information and send it as a value of HTTP-IF-MODIFIED-SINCE in the http request header when we try to access the same url next time.

In the server side, it will check the resource last modified date with HTTP-IF-MODIFIED-SINCE value. If they are the same, it will return 304 HTTP Response. Otherwise, it will return the latest resource by 200 HTTP Response with a new Last-Modified value. Here is an example.
Read more