Updated: July 2019.
FREE WIFIThe easiest alternative is to go to a bar or public place with free internet access.
Since the advent of WhatsApp you can get free wifi in almost all cafe bars and restaurants.
Remember that it might be a good idea to use a VPN if you are using your credit card on a public network.
Hotels and apartments usually have good free wifi.
4G PHONE DATAIf you come from a European country you can just use data using same contract as you do at home. Companies are not allowed to charge more if you are roaming in Europe.
WhatsApp is very popular in Europe and many people don't bother with SMS or actual phone numbers anymore.
If you are not from the EU then you can go to any phone shop and buy some data. It is very useful if you have a dual sim phone so that you can just insert a new sim and still use your own number at the same time.
If you want to by data with no contract then you will need to go to a phone shop and buy a chip which is "prepago".
At the moment of writing the cost is about 8 euros for 1 GB.
A good looking deal is 23GB for 23 euros here at pepephone
https://www.pepephone.com/tarifas-movilesThere are plenty of online forums talking about the best deal currently available.
If you are in another European country before you come to Spain you buy a sim card and it will still work in Spain.
I just spoke to a girl from the US yesterday who bought a Sim in Ireland and is currently using it here for data.