Both of them have positive effect on power factor by injecting local reactive power. Installation of capacitors are mostly used for power factor correction.
Placement of capacitor near load is a good option to improve power factor. However, if loss reduction and power factor improvement can be achieved by placing DG to the most sensitive bus.