Improved algorithm to stop loading javascript and other resources