I have been applying for postdoc positions recently. Yesterday I got an offer from one professor, but I didn't reply to him whether I accept it or not. The reason is that I am waiting for another professor's reply, whose university is much better. But I am not sure the second professor can give me the job. So I am worried to lose all if I refuse the first professor right now. Could you please give me some suggestions to deal with such situations?
I think you are thinking of it backwards. You should use this offer to try to get an early decision from the other professor!
You can say that you're very interested in their position, but you also have another competing offer. You could ask them to make a decision, or give you a timeline for when a decision would be made. Then, to the professor you have the offer from, just write a polite e-mail thanking them for their offer. You can be honest and say you're waiting on a competing offer, or you can say something vague like you need a few days to consider, and give them a deadline (probably no more than 10 days) for your decision.
There are no strict rules on how and when one should respond to an informal offer (offers from academics are considered informal until you hear from HRs officially). Generally, you should treat professors as human beings and apply your best judgement. There is nothing wrong in asking how long you can consider the offer, e.g.
Thank you very much for your offer. I am currently waiting for an outcome of another application. I will be able to give you my answer on DATE. Would it be possible to hold your offer until then?
Obviously, if they agree, you should respect this date and make your decision without further delays. The situation you are facing is not unusual, and there are likely other candidates trying to make their decisions at the same time.
If you were given a deadline to accept or reject the offer, you should respect it. Otherwise you can wait a short time (a few days) before replying. If it is longer than that you need to find an explanation for your delay and ask for a bit more time to consider.
Your situation isn't unique, of course. A few days delay is acceptable, but after a week your offer might be withdrawn if you don't explain.
But it is also acceptable to ask for a fairly short delay before giving a final answer. I doubt that you even need to give a reason. That could be the basis for an earlier reply.