Hairspray does prevent lice infestation to some extent. Lice survive on the head of the host by attaching themselves to the hair shaft. Applying hairspray or hair gel coats the hair shaft, making it more difficult for lice to hold onto.
The main way to prevent a lice infestation is to not share hair accessories. Each person should have their own hair clips, hats, grooming supplies and ear buds to prevent the spread of lice. Each person should respect the personal space of others and avoid head-to-head contact. Some over-the-counter products containing ingredients such as rosemary, tea tree oil, citronella and eucalyptus claim to repel and prevent lice.