The efficient operation of power system is utmost important for reliable power supply to customers. Compensators such as the distributed generation (DG) and power electronics-based devices play the major roles in this regard. In this paper, two kinds of compensators, DG and unified power quality conditioner (UPQC), are allocated to minimize the real power loss and improve voltage indices. In order to achieve this purpose, the loss sensitivity factor (LSF) is utilized to find the specific nodes for the DG and UPQC and then the firefly algorithm (FA) is used to find the sizing and location of DG and UPQC among the estimated nodes. The proposed work is accomplished on IEEE 34 and 69-bus systems. Obtained results are compared with other existing approaches and found better. It is reveal that the proposed approach is effective for the optimal sizing and placement of custom devices with DG simultaneously.