Rather as this history describes, the Thai monarchy and government appears to have modernized (Westernized?) just in time to be able thread a needle between two empires, playing them off each other to maintain independence.
It is worth noting that the word "Thai" has come to mean "free" in the eponymous language. Thailand literally means "land od the free".
Note that this history conveniently ends before World War II.