Spray foam is considered the "best" of all the insulation materials however it is not the best for all situations or circumstances.
The most important thing to know is that there
are two (2) types of spray foam:
1) Open cell low density spray foam
2) Closed cell high density spray foam
Open cell foam is recommended for use mainly in commercial applications. The material is less expensive but requires more depth to achieve vapor barrier. Due to the porous, spongy nature of the product, rodents can easily pull this material apart to gain entry to your building and to build nests. There can be issues with this type of foam curing properly as well as lengthy periods of "off-gassing" which can impact people and pets.
Closed cell foam has the highest R-value available in insulation materials. Spray foam is not the only or necessarily the best insulation material for all types of projects. There are a number of different options that are less costly than foam and are also quite effective in achieving the comfort you desire.