First of all, you must not wash the whites with other clothes as there is possibility of colour bleeding. You should wash them separately.
You should not make piles of dirty clothes and wait for the weekend to wash them. Remember, the stains from perspiration are one the biggest reasons of yellowing. You can avoid this by washing your whites immediately after wearing. Even if you do not have time to wash then you should at least soak them. This will help you to remove all these stains with much less effort.
The most common mistake people make is to use cold or fresh water. This can set the stains and you will have to spend more time in rubbing your shirts. Use warm or hot water as it makes things easy for your detergent and washing machine. However, make sure that your whites are pre-treated otherwise even hot water cannot remove stains properly.
Another technique to keep whites looking bright is to use bleach. However, you must keep in mind that bleaching can weaken the integrity of your fabric so avoid it if garment tags have words of warning. You can use oxygen bleach to reduce the effects of bleaching on fabric.
Remove all the stains properly before washing them for a final time. Using a soft toothbrush can be really helpful in placing the stain remover into the fabric. Moreover, it also removes dirt in less time without damaging the fabric.
Usually, food stains are the most difficult ones to remove but if you have pre-treated your white clothes then a sufficient amount of detergent will wash them away.
Instead of using a dryer, you should dry your whites under the sun. However, do not do this in summers as strong sunbeams will make them pale.