Lateral Code
A Web Development Blog Focused on Code and Technology
Currently Browsing: Home » 2008 (Page 2)
Archive for 2008
GZip files with .htaccess and PHP
By Patrick Lin on Sunday, December 21st, 2008 | Tags: htaccess, php, tutorial | 20 Comments »
Many hosts have a set bandwidth clients can use. In this day and age, files are getting larger and heavier, but bandwidth costs aren’t getting much cheaper. So, one of the best and easiest things to do is to GZip.
From “The Definitive Post on GZipping your CSS”
CSS files for larger sites can become pretty large themselves. Gzipping or compressing these files has shown to provide a reduction in the neighborhood of 70-80% of the original file size, a fairly significant ‘weight loss’.
So obviously, GZipping CSS is great. But what about JS? JavaScript files are becoming increasingly huge, so what should we do about that?
PHP Includes
By Karthik Viswanathan on Sunday, December 7th, 2008 | Tags: php | 2 Comments »
Let’s say you had a website with two pages and a navigation bar on each page. Now assume that you have to change this navigation bar. The basic way to do this would be to go into each file and change the HTML markup.
With just two pages, this isn’t much of a hassle. But what about five pages? How about 20? 100? As you can see, this method is just unreasonable as your website increases in size.
Many web developers solve this problem with PHP includes. PHP is a server-side scripting language whose files can contain HTML markup and the ability of using PHP:
<?php
// php code is placed here
?>
Looking back at the problem, we need a way to change the navigation bar on all the files efficiently. Because we will be using PHP, all the files need to be changed to a .php extension. Once this is completed, we can look at the PHP include_once function.
Toggling Visibility with JavaScript
By Karthik Viswanathan on Saturday, December 6th, 2008 | Tags: javascript | 3 Comments »
Have you ever seen a link that toggles an element’s visibility? It can blend in to create an interactive web page. JavaScript enables web designers to achieve exactly this.
Before we can actually code this effect through JavaScript, we must have an understanding of the CSS (Cascading Style Sheet) display property.
For those of you who are unfamiliar with CSS, a property of an element defines a certain attribute. For example, the CSS property width defines the width of an element.
In this tutorial, we will be focusing on two possible values for this property – block and none. A display value of none hides the element from the viewer. Block shows the element as a block-level element, which is the default setting for most text and is normally visible.
To set the display style of an element in JavaScript, we use the following line:
object.style.display = value;