My hosting provider (goDaddy) seems to be adding eTags to my files.

However I've noticed that they are not appearing on .PHP file (they are on .HTM, .CSS, .JS and images). Is this normal?

From my reading up on etags there doesnt seem to be much you can do to configure them. Or is there something I can add to .htaccess to get etags on all files?


This is normal for dynamic pages. An ETag is a unique identifier for that version of a particular file. The web server can automatically set ETags for static files (html, css etc.), because it can work out when their contents were last changed by looking at the file's last modified time (and some other attributes). There's no way for the web server to know when the HTML generated by your PHP scripts last changed because it is generated on the fly.

You can manually set an ETag from within the PHP script using PHP's header function, but you should only do that if you have a way to generate a unique identifier that will change when the content changes. Generally dynamic pages don't set ETags.

| improve this answer | |
  • ok that makes sense - thank for the explanation. I guess I could generate the etag based on the modified data of the file? – spiderplant0 May 11 '13 at 23:03
  • If you mean the modified date of the PHP script, this is risky, but it depends a bit on what your script does. Imagine a PHP script that simply outputs the current time - if that script sent an ETag based on it's own last modified date, it would be wrong, as the HTML content would change when the time does but the ETag would not. – Tim Fountain May 11 '13 at 23:05
  • My php file gets all the data with ajax in respose to user input (it just need to be php for access to common constants etc). I guess my situation is a bit unusual. – spiderplant0 May 11 '13 at 23:10
  • Actually your points have prompted me to look into converting the php file into a static .htm file during the minimisiation process (probably simpler than figuring out the etag stuff). Thanks. – spiderplant0 May 11 '13 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.