If you get into this situation assess the value you offer in your current company. If you feel that the company really needs you go straight to your boss and tell him that you have been offered a better job and ask them whether they would like to raise your salary or conditions of service to match your job offer.
If in your view the company really doesn’t need you take a chance at the new job.