This paper studies the cause of low-broadside directivity and high sidelobe levels (SLLs) in compact resonant-cavity antennas (RCAs) (footprint < 8λ 0 2). An approach to determine an optimal near-field distribution to significantly improve the broadside directivity and SLL of RCAs is presented. A near-field to far-field transformation routine developed in MATLAB is used to study the individual effects of amplitude and phase distributions, above the partially reflecting superstrate (PRS) of RCAs. Unlike the direct use of a full-wave simulator design, this new approach allows the designers to understand the individual effects of amplitude and phase distributions in the radiating near-field region, on the broadside directivity and on the SLL in the far-field radiation pattern. A method to realise a desired complex near-field distribution is demonstrated, using a dielectric PRS. The RCA with the new PRS showed a significant improvement of 5.0 and 6.4 dB in the broadside directivity and SLL, respectively, compared with a uniform PRS without compromising the footprint and profile of the antenna. The predictions of MATLAB are validated using computer simulation technology (CST) microwave studio (MWS) and experiments.