Crackers were invented by London confectioner Tom Smith, in 1847, as a development of his bon bon sweets, which he sold in a twist of paper (the origins of the traditional sweet-wrapper). As sales of bon bons slumped, Smith began to come up with new promotional ideas. His first tactic was to insert mottos into the wrappers of the sweetss (cf. Fortune cookies), but this had only limited success.
He was inspired to add the "crackle" element when he heard the crackle of a log he'd just put on the fire. The size of the bon bon had to be increased to incorporate the banger mechanism, and the sweet itself was eventually dropped, to be replaced by a small gift. The new product was initially marketed as the Cosaque, but the onomatopoeic "cracker" soon became the commonly used name, as rival varieties were introduced to the market.