Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

2009/06/25

include library files

If you hosted your site somewhere, your probably wanted to know where the root directory path is, in order to include (or require) some library files, which requires a whole path.

If you hosted on linux system, then it is easy to find it out, by

$docRoot = getenv("DOCUMENT_ROOT");
include ($docRoot . "path/to/yourfile");

However, if you hosted on IIS system, then getenv would not work. Here is a workaround:

require_once(dirname(__FILE__) . '/../includes/utils.php');
require_once(dirname(__FILE__) . '/includes/utils.php');
Note: direname(__FILE__)return the current dir name, so you need to tweak it a bit (for example, ‘..’ means jump up a level) to find out a correct library files.

2009/06/23

Some notes about yslow

Company’s webstie is slow. The boss wanted to know why and I am trying to find out why.

I think form web developer viewpoint, what you can do is optimize the web component. If your site hosted on a bad server, then you effort on optimizing the web component is minor. Anyway Firefox fox yslow seems to be a great tool helping you do the website optimization.

1. make fewer HTTP requests.

I think most of current sites have a same problem that a page contain too many external javascript scripts. yslow suggests to try combining them into one, however, most of time this is not a solution at all because you just could not combine them.

2. yslow suggest move all javascript at bottom.

If you should every javascritp snippets, which are relied to those javascripts at header, is running after document ready, then you may do this. Otherwise, you may break some of them.

3. Minify javascript and css

I do some of them. Just too lazy to do all of this, because you are going to update those minified files, that is pain. You have to edit the unminified version, test it and then minfied it again (unless you have a good eye to modify on a minified file)

4. Add expires headers and compress components with gzip

This can be done by updating apache setting …

5. Use a content delivery network

I think this is a big reason the site is slow, if you site hosted on a fast and stable content  delivery network, then you site is most likely running faster.

Note: Just found that yslow does not recognized old style JavaScript tags, like

<script language="JavaScript" src="/js/ajax.js"></script>
//yslow uses type to determine it is javascript or not
<script type="text/javascript" src="/js/ajax.js"></script>

2009/03/16

A little better practice on web development

Every time working on a new project, I do it on the development box, after getting code done and tested, I load new code to the production. It sounds simple, isn’t it? But sometime it is not that simple, for the environment between production and development is different, so I cannot just simple overwrite the production one when load the new code in, also, sometime I directly changed the code on the production for a small change without updating the code on the development. (not a good practice though, but for the small company’s website, which may a quick way.)

So I think I need some good practices to follow when I start a new project. Here they are,

1. Before change any single file, compare it with the production one. If see any new in the production (usually a very small change), update it back to the development one. Make sure it works on development.

2. Make a copy of the file you are going to work with. Add it into the project’s file list.

3. Work on the files on the development box and test.

4. When code ready, compare each file on the project’s file list, and double check the different between new file and backup file, and make sure any additions also available on the production. 

5. Before loading the new code into production. Make a copy of the code on the production as filename.OLD. Make necessary change on the development code to meet the production’s environment and save as filename.NEW.

6. OK final step, check the order of files need to change, for a big project, the code updated may be done after 9:00pm. Basically it is copy filename.NEW to filename.

In any failures above, just copy the filename.OLD back to filename.

2006/12/06

Buy a server

Good servers have dual processors if not quad or more. SCSI is the bus interface of choice for a good server. This is because SCSI is faster than EIDE when it comes to disk transfer an you can connect up to 16 devices to a SCSI chain where as you can only have 2 on a EIDE chain. SCSI drives can spin upward to 15K RPM's where as most of the fastest EIDE drives are 7200K or 10K RPM. Good servers have redundant power supplies and hot swappable disks. A hardware RAID solution is also common with fast servers. This is not only for performance but also for data safty. In a RAID-5 setup if any one given disk fails no data is lost and a new disk can be added back to the RAID array with out taking the server down thanks to the hot swap function. Graphics is not a priority with servers so they often have a very basic video card. Dual NICs are common for both redundancy as well as performance. You can configure one nic to listen and one nic to talk or you can set one up to be a fall over.

from: http://www.v7n.com/forums/web-hosting-forum/12075-server-vs-pc.html

2006/10/24

Add favorite icon for your web page

Simply put your favorite icon (16 x 16 or 32 x 32 ico file named favicon.ico) on the server into the same directory as the web page. Depending on browser and configuration, the favicon.ico is not always rendered, even if it is in one of the above locations, unless the web page explicitly declares its presence. To declare that your web page has an icon, you add the following 2 lines into the <head> section of your page:

<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">