A nuke just above the surface of an asteroid will blast loose lots of loose bits. The Dart mission showed the "explosive impact" - equivalent to 3 tons TNT blasted about a thousand tons of material from the asteroid and had a major effect on its orbit - about five times as much as the actual impact The best distance is probably as close as we can!!
https://en.wikipedia.org/wiki/Asteroid_impact_avoidance
Note any "Non Impact/Explosion" scenario has to cope with the horrible Rocket equation We need to hit the asteroid a long way out so that the small change in velocity is enough to add up to a miss This means that our "diverter" will need a decent delta V 10 km/sec (about the least that will be needed) to get there in time which means a 40:1 Fuel ratio But if we then have to match velocity we need another 40: ratio Giving a 1600:1 fuel ratio. We could send 100 Kg "bombs" - but not the tons of material needed for any type of rendezvous and push scenario.
The "The bomb blows it all to bits scenario" We should start off with the first bomb a decent distance away - the Dart impactor was the equivalent of 3 tons of TNT on the surface Start with say a 10 Kiloton nuke - but set it off 100 meters out - or 200 meters - more qualified people than I should argue about that!
We would use the data from the first impact to fine tune the distances for the later bombs in the string
Various studies have been done - reference the Wikipedia article - but they seem to have concentrated on stopping a relatively immediate impact - talking about 100 Megaton bombs
If we are diverting a number of years out smaller bomb(s) should be enough and would give us time to modify the operation on the fly