Remove Duplicate Code for Repeated XMLHttpRequest Calls
Reduce Use of Global Variables
Replace var with const and let to avoid unintended bugs due to hoisting or scope.
Use Caching for DOM Element Lookups. Repeated use of document.getElementById() and jQuery lookups is inefficient.
Instead of constantly redrawing all aliens, only update and draw what has changed. Use a flag to track if positions or states have changed before redrawing.
Please review kubeinvaders.js and open me solvable issue to improve code