How do I put up shelving that won't sag?
If you're sagging in the longitudinal direction, support lengthwise. If you can brace or support the entire length of the shelf, you can avoid a lot of the sagging. Sometimes even so much as adding a font lip will go a long way to making the shelves sturdier. Even a 1/2" x 1" strip, fastened with glue and countersunk wood screws will go a long way.

If even more weight needs to be supported, I've painted aluminum angle to the bottom of 40"x 26" MDF Shelves so they support Audio equipment in a cheap entertainment center, supported only by 4 steel pins.

Just remember, whatever you add shouldn't be so heavy as to take away from the load the shelf is intended to carry.

I.E. 2" steel angle on 1" thick boards as shelves may be overkill (ask me how I know)