Archive

Archive for January, 2009

Deploying site with SVN

January 13, 2009 Shaun Seo Leave a comment

Instead of using FTP client to overwrite the entire folder (because you often forget which file needs to be overwritten), you can checkout the contents from the SVN server. This will make deployments quick and easy.

1. go to the root directory of your website.

2. checkout the repo


svn co svn+ssh://user@domain.com/repo/trunk .

3. It’s possible that you need to set ownership to the files.


sudo chown -R : ../html

4. When the folder is setup, just run update from next time.


svn update

Categories: SVN

SVN directory concepts

January 11, 2009 Shaun Seo Leave a comment

1. Trunk: main body of development, originating from the the start of the project until the present.

2. Branch: a copy of code derived from a certain point in the trunk that is used for applying major changes to the code while preserving the integrity of the code in the trunk. If the major changes work according to plan, they are usually merged back into the trunk.

3. Tag: a point in time on the trunk or a branch that you wish to preserve. The two main reasons for preservation would be that either this is a major release of the software, whether alpha, beta, RC or RTM, or this is the most stable point of the software before major revisions on the trunk were applied.

Branching/Tagging in TortoiseSVN is explained at http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-branchtag.html

Categories: SVN

Moving SVN repository

January 11, 2009 Shaun Seo Leave a comment

1. Make a dump of your current repository.

svnadmin dump /path > repository-name.dmp

2. Copy the dump file to the new server/machine.

3. Set up the dump file.

cd /path
svnadmin create repository-name
svnadmin load repository-name< repository-name.dmp

Categories: SVN

svn+ssh access

January 11, 2009 Shaun Seo Leave a comment

After setting up a SVN server at MediaTemple I tried to access it with TortoiseSVN. It kept on asking for passwords even though I’ve entered in the correct one.

1. TortoiseSVN will ask for passwords multiple times depending on the number of different domain folders.
2. Upgrading to the newest version of TortoiseSVN [TortoiseSVN 1.5.6, Build 14908] solved the problem of the program crashing.

Setting the SSH client property stopped the multiple password checks.
C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe -l username -pw password

Categories: SVN

Resetting CSS

January 10, 2009 Shaun Seo Leave a comment

To minimise the effects of browser inconsistencies, it is a good idea to reset CSS at the beginning of the file.

The following works just fine.

* {
margin: 0px;
padding: 0px;
}

I like this because it’s simple and then I can set margins, paddings etc to any required elements.

h1, h2, h3, h4, h5, h6 { margin: 15px 0; }
p, table, dl, ul, ol { margin: 10px 0; }
ul, ol, dl dd { margin-left: 40px; }

or as http://meyerweb.com/eric/tools/css/reset/ suggests, the following reset may be useful.


/* v1.0 | 20080212 */

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}

/* remember to define focus styles! */
:focus {
outline: 0;
}

/* remember to highlight inserts somehow! */
ins {
text-decoration: none;
}
del {
text-decoration: line-through;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
border-collapse: collapse;
border-spacing: 0;
}

Categories: CSS

Making hovering work for IE

January 10, 2009 Shaun Seo Leave a comment

Most browsers support :hover for any HTML elements but IE doesn’t work like that (Surprise!). Read the following article to implement whatever:hover to enable proper hovering for IE 5,6,7 and 8.

http://www.xs4all.nl/~peterned/csshover.html

Categories: CSS

Mapping IP address to host names

January 10, 2009 Shaun Seo Leave a comment

If you are running an internal server linked to a domain name, you won’t be able to access the server using that domain name from internal network.

For example, if www.server.com points to the apache server running on your computer, you have to edit the Windows host file if you want to access your server by using www.server.com

Simpley, go to C:\Windows\System32\drivers\etc and edit the hosts file.
Add the mapping by specifying an IP and a domain name.
e.g. 127.0.0.1 www.server.com

You must restart the computer for it to take effect.

Categories: Windows

Speed Up Your Javascript Load Time

January 10, 2009 Shaun Seo Leave a comment

For more detailed description go to http://betterexplained.com/articles/speed-up-your-javascript-load-time/

1. Compress JavaScript using JSMin or Rhino. You can also just gzip it using the normal zip tools but some browsers will not be able to uncompress it automatically.

2. Optimise JavaScript placement. It is not always a good idea to place all the JavaScript files and the CSS files in the header. Place them right before they have to be loaded in order to display some page elements quickly. This will give the users a sense of immediate reponsiveness.

3. Load JavaScript on demand

function $import(src){
var scriptElem = document.createElement('script');
scriptElem.setAttribute('src',src);
scriptElem.setAttribute('type','text/javascript');
document.getElementsByTagName('head')[0].appendChild(scriptElem);
}

// import with a random query parameter to avoid caching
function $importNoCache(src){
var ms = new Date().getTime().toString();
var seed = "?" + ms;
$import(src + seed);
}

You can test it with the following code.

if (myfunction){
// loaded
}
else{ // not loaded yet
$import('http://www.example.com/myfile.js');
}

4. Combine your JavaScript files. Each file incurs the HTTP request and response costs.

5. Cache your scripts.

6. gzip your scripts.

Categories: Web

How To Optimize Your Site With GZIP Compression

January 10, 2009 Shaun Seo Leave a comment

For more detailed description go to http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/

You can simply set up the site compression by editing the .htaccess file on the server.

For example,

# compress all text & html:
AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3

AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/css

AddType text/html .shtml .php .php3 .js .js.gz
AddType text/css .css
AddOutputFilter INCLUDES .shtml .php .php3 .js .js.gz .css

If you don’t have access to the .htaccess file, you can try this in your php file.

Categories: Web

How To Optimize Your Site With HTTP Caching

January 10, 2009 Shaun Seo Leave a comment

For more detailed description go to http://betterexplained.com/articles/how-to-optimize-your-site-with-http-caching/

There are different methods of caching.

1. Last modified: If the file has been modified since the create date stamped by the local machine, then the file is downloaded again.

2. ETag: Each file gets an unique identifier. If the same file has different ETags then it is time to download that file again!

3. Expires: You set the expiration date for the file. Server is queried only if the files are expired.

4. Max-age: Max age sets the time after which the files expire. For example, Max-age of 86400 means the file will expire in 1 day.

Apache server already takes care of Last modified, ETag cases. For Expires or Max-age, edit the .htaccess file.

Header add "Expires" "Mon, 28 Jul 2014 23:30:00 GMT"
Header add "Cache-Control" "max-age=31536000"

Categories: Web