The word barber comes from the Latin barba for beard, and even in early Rome they knew beards needed to be lubricated to be cut without pain. Water worked okay as long as it was held in place with soap.
Special shaving soaps were being sold by the early 1800s. One of the first was Vroom and Fowler’s Walnut Oil Military Shaving Soap in 1840. Soap was place in a cup, water was added and a brush was used to stir up lather. The first successful brushless shaving cream was Burma-Shave in the early 20th century. It’s mostly remembered for the series of small highway signs in verse. Aerosol spray cans were first used for insecticides during World War II. The first shaving cream in a spray can was in 1950, and pressurized foam soon became popular. Canned shaving creams are about 80 percent water. Other ingrediants can include soap fats and glycerol.
With concerns over aerosols as pollutants, shaving soaps and hand-applied creams have made a bit of a comeback. Because soaps penetrate the beard better than airy foams, they acutally provide a smoother shave.
From”Shaving Cream”, An Uncommon History of Common Things by Bethanne Patrick and John Thompson (New York: National Geographic, 2009), p 197