Fixed Width; Fluid Backgrounds Using a Single Element

Sometimes you may need a layout that calls for fixed width content but a fluid background. You can accomplish this with multiple divs or, if you use the calc function, you can just use one div or element, as exemplified below.

[cc lang=”html”]

This content is 200 pixels wide and wraps after it reaches 200 pixels.

[/cc]

[cc lang=”css”]
div.section {
width: 200px;
padding: 0 calc(50% – 100px);
background-color: blue;
color: white;
}
[/cc]

See the demo at jsfiddle.

Canned Messages Using AutoHotKey

Sometimes you may come across a situation where you need to keep typing the same message over and over again like when you’re replying to customer emails. Most people would save different messages in a text editor like Notepad and use copy and paste to avoid having to retype their messages. However, there’s an even easier way using a Windows program called AutoHotKey. With AutoHotKey, you won’t have to switch windows and copy and paste text. You can create a simple script in a text file and assign it to a certain key and when you click on the key (or combination of keys), the text you saved will be written to where your cursor is (in a text area). Here’s an example script in a file called AutoHotKey.ahk in my Documents folder:

#F1::
Send Thank you for your order. {Enter} Please reply indicating which two kites colors you want. We have blue kites, red kites, and purple kites.
return

Continue reading Canned Messages Using AutoHotKey

Website Image Optimizer / Pre (post?) Processor

Let’s face it. The biggest loads and cause for slow performance of most websites comes from images. While there are many projects that offer automated ways to optimize and process CSS like Sass and Less, these optimizations result in a much smaller performance gain compared to what you get from optimized images. The problem with optimizing images is finding a balance between optimization and maintainability. You want to use sprites to minimize the number of requests but you want to reuse images in multiple pages to simplify maintenance (not have multiple copies of the same image). Assuming that most people view 2 or 3 pages per website during any visit, following is a proposal for an image optimization algorithm. This algorithm would generate two types of image sprites as follows:

  • global.png / global.jpg (for images that appear in all pages, e.g. in the header and footer like the website logo)
  • page-path.png /page-path.jpg (for images that appear in a single page, e.g. about-us.png, about-us.jpg, products-computers.png, products-tvs.jpg, etc)

If a web page is at the URL www.somedomain.com/products/computers/index.html, then the sprite for that page would have the file name products-computers.png and/or products-computers.jpg (slashes are converted into dashes). Continue reading Website Image Optimizer / Pre (post?) Processor

Website Performance: How Heavy are Your Images?

Images in websites help break up long, boring passages of text and make websites look nice. But, they’re also the heaviest resources you can include in your site.  Let’s take the home page of techcrunch.com as an example. With the Google Chrome inspector open to the Network tab and the Images label selected, we load the page and scroll all the way to the bottom (because images are load dynamically as they appear in the viewport). The result in 6.5 MB out of a total of 7.3 MB of data to load the home page came from images alone. That’s a whopping 89% of the page load. Because the images are loaded dynamically as needed, techcrunch.com doesn’t load too slowly. However, there are still many websites that are image heavy and don’t do a good job at optimization or caching at all.

page-load

PHP 5.5, APC Cache, OpCodes, and Yii Framework

Recently, I upgraded my version of PHP from 4.6 to 5.5.6. I had been using the PHP APC cache to improve performance. I’m using the Yii PHP framework and the settings I had in main.config were

‘components’=>array(
‘cache’ => array(
‘class’ => ‘system.caching.CApcCache’,
),

PHP 5.5+ now includes a built-in Zend Optimizer opcode cache so the APC cache is no longer supported. As such, my Yii main.config settings needed to change to

‘cache’ => array(
‘class’ => ‘system.caching.CDummyCache’,
),

in order to work.

Handling Wrapped Words Using whitespace: nowrap

When building a website, you’ll often encounter situations where the title of a section would be just a little too long causing the last word to wrap. Furthermore, this wrapping may only occur in some browsers. You may be inclined to put a BR tag before two or more words so that the title doesn’t look bad but there’s a better way using the CSS whitespace rule.

Create a CSS class as follows:
[cc lang=”css”]
span.nowrap {
white-space: nowrap;
}
[/cc]

and then use it where you would otherwise put a BR tag, e.g.
[cc lang=”html”]
This is a long title where the last word sometimes wraps.
[/cc]

Continue reading Handling Wrapped Words Using whitespace: nowrap

Browser Mixed Content Warnings

When viewing a website, you may sometimes come across a warning about mixed content. This “mixed content” is the loading of some resources encrypted over SSL and some not over SLL (unencrypted / cleartext). This only happens when the URL of the page you are browsing to is secure, e.g. https://www.abdullahyahya.com but some of the resources like css and Javascript files it references are not secure, e.g.  https://www.abdullahyahya.com/style.css or http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js. The mixed content warning doesn’t appear when the URL of the page you are viewing is not over SSL, e.g. https://www.abdullahyahya.com, even if the resources it includes are secure.

To prevent mixed-content warnings, you can do the following:

  • Use protocol-less URLs when referencing resources, e.g. //ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js. This way, the protocol (http or https) used will match that of the parent page’s URL. In this case, you need to make sure your included URLs are accessible over both http and https.
  • Always use secure https URLs when reference resources