Make JavaScript *actually* optional
authorChris Morgan <me@chrismorgan.info>
committerChris Morgan <me@chrismorgan.info>
That is, don’t emit it if it isn’t going to be used.
gitweb.cgi

index 8ece13db4dd92334f9dfee2f880505f0eccb811e..515d80cbded1e58b0ed9d2f5e34280752b23f4df 100755 (executable)
@@ -4310,10 +4310,10 @@ sub git_footer_html {
                insert_file($site_footer);
        }
 
-       print qq!<script type="text/javascript" src="!.esc_url($javascript).qq!"></script>\n!;
        if (defined $action &&
            $action eq 'blame_incremental') {
-               print qq!<script type="text/javascript">\n!.
+               print qq!<script src="!.esc_url($javascript).qq!"></script>\n!;
+               print qq!<script>\n!.
                      qq!startBlame("!. esc_attr(href(action=>"blame_data", -replay=>1)) .qq!",\n!.
                      qq!           "!. esc_attr(href()) .qq!");\n!.
                      qq!</script>\n!;
@@ -4321,17 +4321,20 @@ sub git_footer_html {
                my ($jstimezone, $tz_cookie, $datetime_class) =
                        gitweb_get_feature('javascript-timezone');
 
-               print qq!<script type="text/javascript">\n!.
-                     qq!window.onload = function () {\n!;
-               if (gitweb_check_feature('javascript-actions')) {
-                       print qq!       fixLinks();\n!;
-               }
-               if ($jstimezone && $tz_cookie && $datetime_class) {
-                       print qq!       var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
-                             qq!       onloadTZSetup('$jstimezone', tz_cookie, '$datetime_class');\n!;
+               if (gitweb_check_feature('javascript-actions') || ($jstimezone && $tz_cookie && $datetime_class)) {
+                       print qq!<script src="!.esc_url($javascript).qq!"></script>\n!;
+                       print qq!<script>\n!.
+                               qq!window.onload = function () {\n!;
+                       if (gitweb_check_feature('javascript-actions')) {
+                               print qq!       fixLinks();\n!;
+                       }
+                       if ($jstimezone && $tz_cookie && $datetime_class) {
+                               print qq!       var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
+                                       qq!     onloadTZSetup('$jstimezone', tz_cookie, '$datetime_class');\n!;
+                       }
+                       print qq!};\n!.
+                               qq!</script>\n!;
                }
-               print qq!};\n!.
-                     qq!</script>\n!;
        }
 
        print "</body>\n" .