The best way to defend against a cross-site scripting attack is by using a strong firewall application. However, it is also recommended to take additional precautions while using unnecessary websites. For that matter, you can use the Browser JSGuard as well. It blocks malicious codes from being run in the background.