Macbook is lagging and freezing when connected to WiFi
I figured out the problem was with my network cache. None of the online help worked for me. 

The problem was occurring only for my home WiFi. I connect with the VPN and noticed everything was working smoothly as earlier.

I cleared my DNS cache, and reset the network configurations. I deleted the directory /Library/Preferences/SystemConfiguration/ and run the commands to flush the DNS cache

$ sudo dscacheutil -flushcache
$ sudo killall -HUP mDNSResponder
$ sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache



Make sure to take the backup of the SystemConfiguration just incase. Your system can generate the files later.

Hopefully, this will help anyone else who seems to be having freezing issues when connected to the internet.