The song was written for a New York City revue called Demi-Tasse, which opened in October 1919 in the Capitol Theater. Caesar and Gershwin, who was then aged 20, claimed to have written the song in about ten minutes riding on a bus in Manhattan, finishing it at Gershwin's apartment. It was written partly as a parody of Stephen Foster's "Old Folks at Home", even filching the title for the Swanee lyrics. It was originally used as a big production number, with 60 chorus girls dancing with electric lights in their slippers on an otherwise darkened stage.
The song had little impact in its first show, but not long afterwards Gershwin played it at a party where Al Jolson heard it. Jolson then put it into his show Sinbad, already a success at the Winter Garden Theatre, and recorded it for Columbia Records in January 1920. "After that", said Gershwin, "Swanee penetrated the four corners of the earth." The song was charted in 1920 for 18 weeks holding the No. 1 position for nine. It sold a million sheet music copies, and an estimated two million records. It became Gershwin's first hit and the biggest-selling song of his career; the money he earned from it allowed him to concentrate on theatre work and films rather than writing further single pop hits. Arthur Schwartz said: "It's ironic that he never again wrote a number equaling the sales of Swanee, which for all its infectiousness, doesn't match the individuality and subtlety of his later works."
Jolson recorded the song several times in his career and performed it in the movies The Jolson Story (1946), Rhapsody in Blue (1946), and Jolson Sings Again (1949). For the song's performance in The Jolson Story, Jolson, rather than actor Larry Parks, appeared as himself, filmed in long shot. Although usually associated with Jolson, "Swanee" has been recorded by many other singers, most notably Judy Garland in A Star Is Born.