Twitter RSS

simpleCart(js) + PayPal = E-commerce in minutes

Tuesday, October 28th, 2008

****UPDATE: Version 2 is now available, this post is outdated.  Please go to simplecartjs.com to find out more*****

**update: v1.2: fixed rounding error in price formatting
**update: v1.1: back button works, no trailing comma for options

(if you want to skip right to the example and downloads, check it out here)

Over the past few years, our company has had several clients who have needed a smaller shopping cart, usually to sell just a couple of items. We generally built these small carts using paypal. I realized it would be nice to package this up, and create a lightweight, easy-to-use, flexible shopping cart.

So we made simpleCart(js). The cart is a 10.5kb javascript file that uses cookies to keep track of the items in the cart. SimpleCart(js) doesn’t require any databases or programming knowledge. You simply need to know some basic HTML and have the ability to copy and paste. However, it can easily be expanded to use databases or contain more advanced options.

Setup Paypal

The first thing you will need to do, if you don’t already have one, is set up a free merchant account with Paypal.

Add simpleCart(js) to your pages

Once you have the files downloaded, simply add this snippet to the top of any page you wish to have the cart running on:


<script src="simpleCart.js" type="text/javascript"></script>
<script type="text/javascript"><!--
simpleCart = new cart("you@yours.com");
// --></script>

You will need to replace you@yours.com with the email address you used to sign up to Paypal.

Adding items to the cart

Any page you have the simpleCart(js) running, you can add an item by simply using a link like this:


<a onclick="simpleCart.add('name=[name]','price=[price]');return false;" href="#"> link to add item </a>

You are required to at least have a name and price when adding an item to the cart. However, you can add other fields also. If you want an image to be linked to the item, you can add it like this:


simpleCart.add('name=Shirt','price=6.00','image=images/myImage.png');

Viewing the cart

You may have the cart on any page, and it will update automatically using ajax. To show the cart items on a particular page, you simply need to have an element with the class of “simpleCart_items” on the page. This element will automatically be filled with all of the items in the cart, and will show each field.


<div class="simpleCart_items"></div>

You can use any element (div,a,span,p,etc.) and the values will be put in the innerHTML of that element.

Showing the totals on a page

You can show the total quantity or price on any page by simply having an element with a class “simpleCart_quantity” or “simpleCart_total”:


<div class="simpleCart_total"></div> <span class="simpleCart_quantity"></span> items

Checkout and Empty Cart links

You can have a checkout or empty cart link anywhere on any page where the simpleCart(js) is active. You do this by simply setting the class of an element to “simpleCart_checkout” or “simpleCart_empty”:


<a class="simpleCart_checkout" href="#">checkout</a>

<a class="simpleCart_empty" href="#">empty cart</a>

You can use any type of element for these, and you can put anything inside of the element. Anything wrapped in a tag with those classes will link appropriately.

Other Options

Adding other product options to items.


simpleCart.add('name=Shirt','price=6.00','image=images/myImage.png','size=XL','color=Blue');

You can also change the quantity that will be added to the cart:


simpleCart.add('name=Shirt','price=6.00','image=images/myImage.png','quantity=5','size=XL','color=Blue');

The order of the arguments doesn’t matter, and you can add as many options as you would like.

Styling the cart.

You can style this cart to fit the look of your page. The contents of the cart will start with a header row:


<div class="cartHeaders">
<div class="itemImage">Image</div>
<div class="itemName">Name</div>
<div class="itemPrice">Price</div>
<div class="itemOptions">Options</div>
<div class="itemQuantity">Quantity</div>
<div class="itemTotal">Total</div>
</div>

Each item in the cart will have the following form:


<div class="itemContainer">
<div class="itemImage">[myImage]</div>
<div class="itemName">Shirt</div>
<div class="itemPrice">$6.00</div>
<div class="itemOptions">size: XL; color: Blue</div>
<div class="itemQuantity"><input type="text" /></div>
<div class="itemTotal">$30.00</div>
</div>

And there will also be a totals row:


<div class="totalRow">
<div class="totalItems">6</div>
<div class="totalPrice">$30.00</div>
</div>

You can choose to omit part of the cart in your stylesheet:


.itemOptions,itemImage{
display:none;
}

Or you can hide the header or totals rows:


.totalRow{
display:none;
}

.cartHeaders{
display:none;
}

Change the order of the cart columns.

If you would like to change the order of columns or remove the columns from ever being shown, simply add a line to the top of your page:


<script type="text/javascript" src="simpleCart.js"></script>
<script type="text/javascript">
simpleCart = new cart("you@yours.com");

//Add the following line to reorder and remove item columns
simpleCart.ItemColumns = ['Image','Price','Name','Quantity','Total'];

</script>

Download and Demo

Below are links to download simpleCart(js) and to view a working Demo. One great thing about the cart being stored in cookies is that you can have your items be added on one page and the cart be on another if you wish. The demo reflects this. The main page of the sample store is here and the View Your Cart page is here.

********* Please go to simplecartjs.com for the updated downloads and demo************


Pricing: Hourly or Fixed?

Tuesday, October 21st, 2008

Pricing your projects right is one of the most challenging tasks for freelancers and small business owners. This challenge may be especially difficult for those professionals who are working in the design industry, where it can be very hard to predict how much time and effort will be needed for a project. Ultimately, pricing is a challenge because the client and the professional have opposite interests.

Pleasing the Professional – Hourly Pricing

From the perspective of the freelancer/small business owner, hourly pricing is ideal. You simply add up the amount of hours you spent working on a project, send the client an invoice, and get paid at your hourly rate. Most likely, you would also bill the client for any extra charges incurred on their behalf. This way, you legitimately earn the amount of money that you are worth (or, at least, what you think you’re worth).

Professionals also want to avoid getting trapped into a bottomless project. These projects require way more effort than they’re worth. Perhaps you vastly underestimate the time requirements of a project. Once you have signed a contract and agreed to a fixed quote, there may not be much you can do. Another common problem is scope creep- the tendency for project requirements and expectations to become ever more broad as the project progresses. With an hourly rate, scope creep is not much of a problem for the professional, because they can simply charge for the extra hours required to do the work.

Of course, this pricing model creates the sinister temptation to charge extra hours, to round up hours, and to take a rather liberal definition of ‘work hour’. Can you bill your client an hour of work because you thought about their project while running on the treadmill? The hourly model is simply not suited for truly motivating the professional to be efficient and productive. Obviously, professionals who pad their log sheets with reckless abandon will eventually be dropped, but the temptation to stretch the truth (even subconsciously) can still be very strong. Clients need to have a great deal of trust, and the professional needs to be very trustworthy, for this pricing scheme to work fairly.

Catering to the Client – Fixed Pricing

Clients want to know how much they will have to pay for a project. Smaller clients want to know that they will have enough money to take on the project, and larger clients want to be able to budget out their expenditures as accurately as possible. If you want to make your clients happy, then nine times out of ten you have to provide them a firm quote.

Plus, clients want to avoid the type of exaggeration discussed in the previous section. A fixed quote protects them from being overcharged. It also allows clients more latitude to change or expand upon the requirements for the project. If they think that the designer has done a poor job on an initial design comp, they might not need to pay for it. A fixed price therefore gives the client the upper hand in the business relationship. We’ve certainly been on the bad end of this deal, and certain clients have made us pay the price.

A Middle Ground?

Clients want to know how much they will have to pay for their project. Professionals want to be paid for every hour they work, regardless of the project cost. Can there be a solution to this conflict of interests?

Maybe. It is possible to develop a hybrid model that meets the needs of both. The professional can provide a provisional quote of a project based on an estimate of the number of hours the project is going to require. This quote is not set in stone, however, and the cost at the end of the day may be higher or lower than the set amount. If clients are still weary of this setup, then perhaps you can guarantee that the final price will be within 10 or 20% of the quote. The less room for error, though, the more accurate you must be with your estimate of the time you’ll need to spend on the project.

As our company has developed, our pricing method has been all over the map. We started out with fixed quotes- this, however, was back when we naively thought that we could create a successful business model by drastically undercharging for our services (note: this doesn’t work!) Later, we flirted with the temptation to convert to a strictly hourly setup. In fact, many freelancers refuse to do it any other way. But, ultimately, this was just not always realistic or fair for the clients. So, we’ve settled on trying to use a hybrid model for most of our clients.

Pricing Honestly and Accurately

Whatever pricing method you use, two things are essential: you must strive to price accurately and to price honestly.

Accuracy

Pricing accurately is based on knowing the amount of time and effort you will need to spend on a project. To a large degree this is simply based on experience. That’s why it’s important to always track how much time you actually spend on a project, even if you have already agreed to a fixed quote, or even if you are doing something free (like some nonprofit project, and internal site redesign, or that website for your grandma). Compare your prediction with your results. There are some online tools that can help you do this too- we use Basecamp to track our time but you may want to try a dedicated service like Harvest Eventually, you will get better at making predictions of the time required for projects.

Another important technique- break the project down into its smaller components. When we are quoting a web site design, we break the process down into the following components;

  • Creation of the Information Architecture
  • Wireframing
  • Design Comps
  • Coding the HTML/CSS
  • Programming
  • Debugging
  • Cross-Browsering

Considering the project in smaller chunks makes it a lot easier to estimate the time requirements.

Honesty

Honesty is important for any business relationship. As a freelancer, there is a temptation to exaggerate the amount of hours you have worked. As a client, there is a temptation to expand the requirements for the project and work your designer to death. This is what creates all sorts of distrust between clients and professionals. But if you want a truly productive and satisfying relationship, you will need to trust each other. At the end of the day, if both parties are honest and fair about the project, pricing should not be a big problem.


Motionspire Beta Launch – We Need Your Help!

Sunday, October 19th, 2008

We recently launched the Motionspire beta. We’ve been developing this site for quite some time, and we’re finally opening it up to some users.

The concept behind Motionspire is very simple- we built the site to be the best place to view inspirational motion graphics content. Taking a cue from the CSS gallery concept, which has been implemented well by sites like cssmania, cssremix, and stylegala, among others, we thought that there should be a website where you can go to simply view some good motion graphics.

Instead of doing a full launch, we decided to start off with a beta model, for several reasons. First, it gives us a chance to get some good feedback from beta users before we go ahead with the global launch. We are always open to suggestions to make this site better for its users. Second, the beta launch gives us a chance to track some statistics so we can accurately gauge the resource requirements we’ll need for the site.

With that in mind, we need your help. If you are interested in this project, head on over to motionspire.com and fill out a beta account. It’s really easy, and it will give you the chance to be one of the first to try out this new endeavor. Thanks!


5 Ways the Web Can Help Us Eliminate Poverty

Wednesday, October 15th, 2008

Blog Action Day

Today is Blog Action Day, and bloggers around the world are uniting to discuss the issue of poverty. We live in a unique time in history- the need is massive but we have the resources to respond. Never before in history have we been in a position to make such huge inroads into needless human suffering.

An evidence of this fact is the creation of the Millennium Development Goals by the United Nations. The MDGs hope to radically reduce the amount of poverty and pointless suffering that happens worldwide by 2015. The goals are;

1. Eradicate extreme poverty and hunger.
2. Achieve universal primary education.
3. Promote gender equality and empower women.
4. Reduce child mortality (by two-thirds).
5. Improve maternal health (reduce maternal mortality by three-fourths).
6. Combat HIV/AIDs, malaria and other diseases.
7. Ensure environmental sustainability.
8. Develop a global partnership for development.

These goals are very ambitious, but actually realistic. Realistic, that is, as long as we make a sustained commitment to combating these ills. The fact that we can reasonably expect to achieve these remarkable goals is a testimony to the unprecedented amount of resources and infrastructure we have in place to make a difference.

With that in mind, let’s take a look at 5 ways we can use the Web to combat global poverty.

1.) Awareness

While ignorance may be bliss, it is no longer excusable. If you have the Internet at your fingertips, then you can easily and quickly learn about the extent and impact of poverty in the world. And the figures are pretty disturbing.

  • 26,500-30,000 children die each day due to poverty.
  • Every year there are 350–500 million cases of malaria, with 1 million fatalities (malaria is easily preventable).
  • Over 3 billion people live on less than $2.50 a day (less than a Starbucks latte).

Whether or not we are aware of the exact statistics, we are certainly more aware than ever about how bad the problem is. Make a commitment to staying informed about poverty. And, make a commitment to inform others too.

2.) Accountability

With greater awareness comes greater accountability- organizations can no longer easily sweep their moral failings under the rug. Using child labor? You may just get caught. And now, information can be spread quickly and broadly.

Accountability is not only important for corporations, but for nonprofits as well. Be sure to check out resources like Charity Navigator to ensure that you are committing your hard earned dollars to responsible charities that actually make a difference in the lives of those they serve.

Finally, accountability is important for government as well. It is time for us to call out politicians for their unfulfilled promises. Did you know that out of 22 countries who promised to contribute .7% of their annual income towards the Millennium Development Goals, only five are actually keeping their promises? My home country, the United States, is ranking at the bottom of the list, only managing to offer a meager .16% so far, with no scheduled plan to reach the promised amount.

3.) Advocacy

The power of the Web can be harnessed to advocate for the cause of the poor. Organizations like One can help us stay informed and communicate our concern to politicians. The fight to eliminate poverty depends to a great deal on the support of government. In order to succeed, we need to make sure politicians know there will be consequences if they fail to live up to their promises and they fail to fight against poverty. Take a stand against poverty today.

4.) New Ideas

The Web is the springboard for a lot of new ideas, including new ideas for fighting poverty. One of the most exciting developments is kiva.org, a site that gives you the chance to lend to entrepreneurs in the developing world. While lending to extremely poor individuals in developing countries may not sound like the wisest investment choice, in fact repayment rates in the best programs are very high. Kiva boasts a repayment rate well above 99%. Given the state of the stock market, this may actually look like a fairly wise place to put your money.

I’ve actually done independent research on microfinance, and studies show that these programs can be very effective. One measure of their success vs. other opportunities is the cost-benefit ratio, which measures the amount of cost to society compared to the benefit to clients. For the Grameen bank, a bank that offers a microfinance program akin to Kiva’s, studies indicated that the cost-benefit ratio for loans to women was .91 – much better than some alternatives like the World Food Program’s Food-for-Work scheme (ratio: 1.71). 1 The bottom line: Microfinance programs are a great way to combat poverty.

Moreover, these programs create many side-benefits. For example, these programs have been very successful in empowering women (the third Millennium Development Goal). The vast majority of applicants to microfinance programs (well over 90%) are women. These programs are giving women employment opportunities and independence in traditionally male-dominated cultures. And, microfinance programs have had measurable and positive impacts on maternal health (MDG 5) and child education (MDG 2). 2

The upshot: using the power of the Web, we all have the opportunity to support entrepreneurship, creativity, and independence for those in developing countries.

5.) Harnessing the Support of Individuals

When it comes to combating poverty, individuals really can make a difference. The power of the Web has opened our eyes to this fact. Using the Web, individual efforts can be congregated to produce something all the more powerful. In fact, this concept is the driving force behind organizations like kiva.org and one.org.

The Web also gives us the opportunity to gather together in communities with a broader scope than ever before. There are an explosion of facebook groups, blogs, and online communities where people all across the globe are joining together to discuss their passion for eliminating poverty.

Just Do It

All the tools and techniques in the world won’t make a whit of difference unless you make a personal commitment to do something. There are a million ways we can help. Why not forgo one restaurant visit a month in order to support a child? Instead of buying a new car, buy an ox for a family overseas. Instead of investing in the (plummeting) stock market, invest in the business opportunity of an entrepreneur at kiva.org.

True, these kinds of actions may cut into our paycheck. They may make our lives a little less luxurious. But it may make the difference between a child dying slowly of starvation and that same child living a long, productive life. That’s a difference that may be worth a few forgone lattes.

NOTES:

Morduch, Jonathan. “The Microfinance Promise.” Journal of Economic Literature 37.4 (1999): 1569-1614.

Littlefield, Elizabeth, Syed Hashemi, and Jonathan Morduch. “Is Microfinance and Effective Strategy to Reach the Millenium Development Goals?.” Focus Note 24 (2003): 1-12.



10 Easy Steps to Great Website Optimization.

Sunday, October 12th, 2008

You could write a book on website optimization, in fact people already have. But, here’s 10 really easy steps to getting your sites optimized for speed. Hopefully this will get you started and you’ll want to investigate front end optimization a little further.

1. Run your images through smushit.com.

While it’s obvious to keep your image sizes down as low as possible, it’s not as obvious that some image editing programs like photoshop can add extra meta and formatting data in your images. Its viewable if you open the image in a text editor. Smushit is a firefox plugin that strips out all of this extra formatting and can reduce your image sizes without sacrificing quality. Once the plugin is installed, simply go to the webpage you want to optimize, click the smushit icon in the bottom right of your firefox window, and smushit will tell you how much you can save on each image as well as give you a zip file filled with the smushed images.

2. Use the Fastest CSS Selectors.

When styling elements with CSS there are many ways to specify what you’re styling and some of those ways are faster than others. According to this study by John Sykes, you should first try to just style tags:

a

the next fastest way to select something in css is by class:

.link

Then its descenders:

div div div p a.link

finally the slowest is child selectors:

div > div > div > p > a.link

3. Combine all of your non-repeating background images into one giant sprite.

Reducing HTTP requests is a huge part of website optimization and images can be the biggest culprit. So one easy thing to do is combine all of you background images that don’t repeat into one big image. Most time it helps to not put any spaces between the images and to build the sprite horizontally to make the smallest image. Then in your css you can specify the background image like this…

>.myClass{
background:url(images/bigImageSprite.png) -12px 0 no-repeat;
}

( “-12px 0″ specifies to display the image 12px to the right and 0px down)

4. Run all of your css and JS files through compressors.

Keeping code file sizes down is another no brainer. So run your CSS and JS through optimizers/compressors. For your CSS stylesheets there are plenty of optimizers out there. In fact there is a great round up and review of many of them here. I agree with the round up that the Icey CSS Compressor does a great job. In fact it reduced the stylesheet of this blog by 23%.

When it comes to compressing your JS the best service is Yahoo’s YUI compressor. Other services are either unsecure, or don’t do as well a job. You can download the YUI compressor here. Or you can use this online version from refresh-sf.com. While we’re on the subject of compressing your JS, Prototype and Scriptaculous could use some compressing. So if you use those frameworks get the compressed version aka Protopacked.

5. When saving images, try jpg, png, and gif.

There is no one image file type that always yields the smallest file sizes. So when possible try all of them. Of course there are times that a jpg just won’t guarantee the correct colors that you need, but when you can try exporting your images as each type and see which is the smallest. Photoshop’s “save for web and devices” feature is great for this. It tells you what the file size will be before you have to actually export the images.

6. Place <script> tags at the bottom of the page.

This one isn’t always possible, but try as much as you can to put all your scripts at the bottom of the page. When a browser is downloading the assets to a page it goes through your html file to find what to retrieve. It generally downloads multiple items in parallel  (we’ll discuss that more later), but since a script can change anything and everything on the page it stops everything and downloads just that one script file. So if you put it at the end the browser will download everything as fast as possible first, then it will download your scripts.

7. Attach external scripts without blocking parallel downloads.

If you can’t put your <script> tags at the bottom there is a way you can put them in your page without blocking parallel downloads. You can do this in a variety of methods, but each has their own pro’s and cons. My personal choice is to add the <script> tag via the DOM. This allows you to have a download progress indicator in at least firefox (no IE, sorry), and to put your scripts on subdomains (see rule 8).


var js = document.createElement('script');
js.src = 'scriptName.js';
js.type = 'text/javascript';
var head = document.getElementsByTagName('head')[0];
head.appendChild(js);;

For more options see Steve Souder’s power point presentation on “Even Faster Websites”.

8. Put assets on sub-domains to increase parallel downloads.

The idea behind this tip is that browsers only download 2 items in parallel per domain. This is part of the HTML 1.1 spec. So if we can download 4 or even 8 things at a time we’ll get faster page downloads. To get more downloads to run in parallel we use the loophole in the “2 downloads per domain” rule, namely, the fact that it says, “per domain”. So make some sub-domains and spread your assets out. I recommend putting your images on one and your html, css, and scripts on another.

However, you must keep in mind that it’s not advisable to have too many DNS lookups in your pages. Each sub-domain forces the browser to do a DNS lookup which hurts speed. The yahoo performance team did some research on this area and came up with the conclusion that you should use at least 2 but no more than 4 host names.

9. Disable E-tags

E-tags are a way that servers check to make sure the file in your cache is the same file that’s on the server. It basically applies a unique identifier to each asset to do this. The problem is that when your site is on a server farm and multiple servers are processing requests, the e-tag will fail from server to server. It will match on the first server but will fail on the rest, thus forcing you to re-download the file that it already cached.

Disabling E-tags only really helps those sites that are on such server farms, so if you’re on a shared host its not always going to help, but it is still recommended because shared hosts routinely change servers and you might even change hosts as well. Plus it’s drop dead simple. Add the following line to your .htaccess:

FileETags none

10. Gzip your components.

Ok so this one might not fit into the “Easy Steps” part of this list, but in some cases it will. The basic idea here is to, once again, reduce file sizes. By Gzipping your components you’re reducing the file sizes of the browser’s downloads.

There are several methods you can use to Gzip your files, but depending on your server and host it might become tricky. The easiest way to do it if you’re running Apache is to first verify what version of Apache you’re running. To do this you can use firebug and look in the net panel for the server response header. You should see it.

There is also a good chance your host has the Apache version stated in the control panel somewhere.

If your Apache is version 1, add the following to your .htaccess file in your root directory:

mod_gzip_on Yes

mod_gzip_item_include mime ^application/x-javascript$
mod_gzip_item_include mime ^application/json$
mod_gzip_item_include mime ^text/.*$

mod_gzip_item_include file \.html$
mod_gzip_item_include file \.php$
mod_gzip_item_include file \.js$
mod_gzip_item_include file \.css$
mod_gzip_item_include file \.txt$
mod_gzip_item_include file \.xml$
mod_gzip_item_include file \.json$

Header append Vary Accept-Encoding

If you have Apache 2 add this to the .htaccess file instead:

AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml
application/x-javascript application/json
Header append Vary Accept-Encoding

There are many situations where your shared hosts will not allow you to edit your .htaccess file or editing it to enable gzip just won’t work. If thats the case follow this post from fiftyfoureleven.com. It shows a variety of ways to achieve this, some using php.

Further Reading

This article just scrapes the surface of out what’s there as far as website optimization. I hope this at least gets you thinking in terms of optimizing your sites. If you’d like to read more I highly encourage reading Steve Souder’s blog, Website Optimization Secrets (O’Reilly), and the Yahoo Optimization page (which used to be captained by Steve Souder). Also be sure to check out YSlow, and the Webkit Element Inspector (also found in chrome).