After the success of Wilde's plays Lady Windermere's Fan and A Woman of No Importance, Wilde's producers urged him to write further plays. In July 1894 he mooted his idea for The Importance of Being Earnest to George Alexander, the actor-manager of the St James's Theatre. Wilde summered with his family at Worthing, where he wrote the play quickly in August. His fame now at its peak, he used the working title Lady Lancing to avoid pre-emptive speculation of its content. Many names and ideas in the play were borrowed from people or places the author had known; Lady Queensberry, Lord Alfred Douglas's mother, for example, lived at Bracknell.[n 1] There is widespread agreement among Wilde scholars that the most important influence on the play was W. S. Gilbert's 1877 farce Engaged; Wilde borrowed from Gilbert not only several incidents but, in Russell Jackson's phrase "the gravity of tone demanded by Gilbert of his actors".
Wilde continually revised the text over the next months: no line was left untouched, and "in a play so economical with its language and effects, [the revisions] had serious consequences". Sos Eltis describes Wilde's revisions as a refined art at work: the earliest, longest handwritten drafts of the play labour over farcical incidents, broad puns, nonsense dialogue and conventional comic turns. In revising as he did, "Wilde transformed standard nonsense into the more systemic and disconcerting illogicality which characterises Earnest's dialogue". Richard Ellmann argues that Wilde had reached his artistic maturity and wrote this work more surely and rapidly than before.
Wilde hesitated about submitting the script to Alexander, worrying that it might be unsuitable for the St James's Theatre, whose typical repertoire was relatively serious, and explaining that it had been written in response to a request for a play "with no real serious interest". When Henry James's Guy Domville failed, Alexander turned to Wilde and agreed to put on his play. Alexander began his usual meticulous preparations, interrogating the author on each line and planning stage movements with a toy theatre. In the course of these rehearsals Alexander asked Wilde to shorten the play from four acts to three. Wilde agreed and combined elements of the second and third acts. The largest cut was the removal of the character of Mr. Gribsby, a solicitor who comes from London to arrest the profligate "Ernest" (i.e., Jack) for his unpaid dining bills. Algernon, who is posing as "Ernest", will be led away to Holloway Jail unless he settles his accounts immediately. Jack finally agrees to pay for Ernest, everyone thinking that it is Algernon's bill when in fact it is his own. The four-act version was first played on the radio in a BBC production and is still sometimes performed. Peter Raby argues that the three-act structure is more effective, and that the shorter original text is more theatrically resonant than the expanded published edition.