The single most important thing: wet your hair before you swim
Wet hair before getting in the pool or the sea. Dry hair is porous and absorbs whatever it comes into contact with first. If you wet it with fresh water beforehand, it absorbs the clean water and has less capacity to take on chlorinated or salt water. Follow it up with a leave-in treatment and you've created a real barrier between your colour and the elements.