In the previous work [Metzler et al., Phys. Plasmas 6, 3283 1999] it was shown that a tailored density profile could be very effective in smoothing out the laser beam non-uniformities imprinted into a laser-accelerated target. However, a target with a smoothly graded density is difficult to manufacture. A method of dynamically producing a graded density profile with a short shaping laser pulse irradiating a foam layer on top of the payload prior to the drive pulse is proposed. It is demonstrated that the intensity and the duration of the shaping pulse, the time interval between the shaping pulse and the drive pulse, and the density ratio between the foam and the payload can be selected so that the laser imprint of the drive pulse is considerably suppressed without increasing the entropy of the payload. The use of the foam-plastic target and a shaping pulse reduces the imprinted mass perturbation amplitude by more than an order of magnitude compared to a solid plastic target. The requirements to the smoothing of the drive and shaping laser beams and to the surface finish of the foam-plastic sandwich target are discussed.