--- a/lib/filelib.php
+++ b/lib/filelib.php
@@ -53,6 +53,10 @@ function get_file_url($path, $options=null, $type='coursefile') {
         $separator = '&amp;';
     }
 
+    // Cache
+    $lastmodified = filemtime($CFG->dataroot . '/' . $path);
+    $options['ver'] = $lastmodified;
+
     if ($options) {
         foreach ($options as $name=>$value) {
             $ffurl = $ffurl.$separator.$name.'='.$value;
@@ -786,6 +790,20 @@ function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathiss
         @header('Accept-Ranges: none'); // Do not allow byteserving when caching disabled
     }
 
+    // Start Etag Support
+    $etag = '"' . md5($lastmodified) . '"';
+    if (!empty($_SERVER['HTTP_IF_NONE_MATCH'])) {
+        if ($_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
+            @header('HTTP/1.0 304 Not Modified');
+            @header('Content-Length: 0');
+            @header('Etag: ' . $etag);
+            die();
+        }
+    } else {
+        @header('Etag: ' . $etag);
+    }
+    // End Etag Support
+
     if (empty($filter)) {
         if ($mimetype == 'text/html' && !empty($CFG->usesid) && empty($_COOKIE['MoodleSession'.$CFG->sessioncookie])) {
             //cookieless mode - rewrite links
