I’m trying to prevent caching by appending a ‘? t=’ to the end of my JS files. What’s the fastest way to get such a number? time() or rand() or something else?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
time()andmt_rand()are pretty similar in terms of efficiency in PHP – you select one or the other based on what factors you need it for:mt_rand()(e.g., generating use salt)mt_rand(1, 931415926536);(e.g., generating session id)time()(e.g., prevent caching, logs etc)If you really want to know,
time()is slightly faster—but you really don’t need to worry about it. (It’s the difference between one or two small parts of a second.)Note that
rand()is now an alias tomt_rand()since PHP 7.1:You probably know this already, but be sure to always profile your code before making optimizations; often it’ll run slowly for reasons completely different than what you expected.