In the case of larger airports in Canada, they use computer technology to avoid it. So if you flying Sweden->Toronto-> New York, you will clear US customs in Toronto and the bags are automatically transfer US Customs in Toronto is show photos of the bag on a screen and they can have the baggage system bring them up for inspection or release them to the next flight. Same would happen if it was Sweden->Toronto-> Vancouver.
If Europe they do immigration when you first land, then customs at your final destination. The baggage tags have a green strip on the side if they originate locally and no color code if they are form outside the customs zone.
Nothing would stop US airports from using the same computer systems they use in Canada other than the cost of upgrading the airprot.