For iMacs, generally, "newer is better".
The only weak spot with the 2017 is 8gb of RAM. RAM on the 21" iMac is not really "user upgradeable" (entire computer must be disassembled).
However, 8gb will still probably do the job well for the use case you mention above.
So... of the two choices... I'd buy the 2017.