This is apropos of nothing, but I was idly curious after hearing a prominent conservative pundit refer casually to Middle Easterners as "ragheads" as to where this term comes from. I had a faint recollection that it originally had nothing to do with Arabs or Persians, and wondered if it perhaps dated from the nineteenth century British Raj. Turns out I was half right.
Oddly, the term (according to the Oxford English Dictionary) can be traced back only as far as the University of California, where it was used to describe any "Asiatic" wearing a turban, circa 1921. The term has since metastasized, obviously, but the OED offers no indication of when the term was first used for Arabs or Persians.
The OED is clearer on the term "gook," which underwent a similar shift. Originally used in the US to refer to Spanish-speakers and/or Filipinos, it was increasingly used to describe Koreans, Japanese, and (eventually) Vietnamese.
No real point to make about all this, except that it is interesting that both terms appear originally to have described immigrant communities in the US, but migrated abroad to fill the need for racial or ethnic slurs in new contexts. Americans don't have a ready term to use to denigrate the leaders of Iran, so when needing to get bigoted-up, some borrowing must be done.