For an ordinary vented attic, I'd generally air-seal the ceiling first, then add blown cellulose or fiberglass, keeping the soffit ventilation paths clear. Small amounts of foam can help seal suitable gaps even when you use fibrous insulation for most of the attic. [DOE air-sealing guidance](https://bsesc.energy.gov/energy-basics/air-sealing-existing-attics)

People do use foam in attics, but its extra cost often adds little benefit in a conventional vented attic. Whether you're insulating the attic floor or the roof makes a difference.

On the attic floor, fiberglass or cellulose is usually economical because there's room for a thick layer. Blown insulation fits around joists, wiring and other obstructions without requiring you to cut and seal lots of rigid boards. Foam's higher insulation value per inch is more useful where space is tight. [DOE insulation guide](https://www.energy.gov/sites/prod/files/2013/11/f5/insulation_guide.pdf?trk=article-ssr-frontend-pulse_little-text-block)

Rigid foam boards need careful fitting and sealing: gaps between boards and around framing can reduce their performance. Spray foam depends heavily on installation quality and makes it harder to reach components it covers. Foam plastics also have fire-protection requirements. Depending on the product and how the attic is used, you may need an approved barrier or protective coating. [Residential Spray Foam Guide](https://buildingscience.com/documents/guides-and-manuals/gm-2102-residential-spray-foam-guide)

Spray foam under the roof deck is a different project. It's commonly used to create an unvented attic within the home's thermal enclosure, which can benefit HVAC equipment and ducts located there. The design needs to account for ventilation, humidity and vapor control together. An unsuitable assembly can allow moisture to accumulate at the roof sheathing. [Building Science guidance](https://buildingscience.com/documents/building-science-insights-newsletters/bsi-119-conditioned-unconditioned)

Before settling on R-30, check the recommended insulation level for your climate. Current U.S. recommendations reach R-49 or R-60 in many regions. [ENERGY STAR recommended R-values](https://www.energystar.gov/saveathome/seal_insulate/identify-problems-you-want-fix/diy-checks-inspections/insulation-r-values)