vadvs (vadvs) wrote in changelog,
vadvs
vadvs
changelog

[livejournal] r21771: LJSUP-11897: System to organize JS/CSS s...

Committer: vad
LJSUP-11897: System to organize JS/CSS sources into a libraries
U   trunk/cgi-bin/ljlib.pl
U   trunk/cgi-bin/weblib.pl
Modified: trunk/cgi-bin/ljlib.pl
===================================================================
--- trunk/cgi-bin/ljlib.pl	2012-04-20 12:40:03 UTC (rev 21770)
+++ trunk/cgi-bin/ljlib.pl	2012-04-20 12:47:16 UTC (rev 21771)
@@ -2373,48 +2373,6 @@
     # reload config if necessary
     LJ::Config->start_request_reload;
 
-    # include standard files if this is web-context
-    unless ($LJ::DISABLED{sitewide_includes}) {
-        if (LJ::Request->is_inited) {
-            # standard site-wide JS and CSS
-            # jQuery always should be the first in the list
-            LJ::need_res(qw(
-                            js/jquery.js
-                            js/jquery_fn.js
-                            js/basic.js
-                            js/livejournal.js
-                            js/jquery/jquery.ui.core.min.js
-                            js/jquery/jquery.ui.widget.min.js
-                            js/jquery/jquery.tmpl.min.js
-                            js/jquery/jquery.lj.basicWidget.js
-                            js/jquery/jquery.lj.bubble.js
-                            stc/lj_base.css
-                            ));
-
-            # esn ajax
-            LJ::need_res(qw(
-                            js/esn.js
-                            stc/esn.css
-                            ))
-                unless LJ::conf_test($LJ::DISABLED{esn_ajax});
-
-            # contextual popup JS
-            LJ::need_res(qw(
-                            js/ippu.js
-                            js/lj_ippu.js
-                            js/ljwidget.js
-                            js/ljwidget_ippu.js
-                            js/hourglass.js
-                            js/contextualhover.js
-                            stc/contextualhover.css
-                            )
-            ) if LJ::show_contextual_hover();
-
-            # Conditional IE CSS file for all pages
-            LJ::need_res({condition => 'lte IE 8'}, 'stc/ie.css');
-        }
-    }
-
     LJ::run_hooks("start_request");
 
     return 1;

Modified: trunk/cgi-bin/weblib.pl
===================================================================
--- trunk/cgi-bin/weblib.pl	2012-04-20 12:40:03 UTC (rev 21770)
+++ trunk/cgi-bin/weblib.pl	2012-04-20 12:47:16 UTC (rev 21771)
@@ -1313,13 +1313,27 @@
         @LJ::NEEDED_RES = ();
         return;
     }
+    
+    foreach my $key (@keys) {
+        my $reskey  = $key;
+        my $resopts = $opts;
+        if (ref $reskey eq 'ARRAY'){
+            $reskey  = $key->[1];
+            $resopts = $key->[0];
+        }
 
-    foreach my $reskey (@keys) {
         die "Bogus reskey $reskey" unless $reskey =~ m!^(js|stc)/!;
+
+        ## is the key part of library/package
+        if (my $library = $LJ::JS_SOURCE_MAP_REV{$reskey}){
+            $reskey = $library;
+        }
+
         unless (exists $LJ::NEEDED_RES{$reskey}) {
             push @LJ::NEEDED_RES, $reskey;
         }
-        $LJ::NEEDED_RES{$reskey} = $opts;
+
+        $LJ::NEEDED_RES{$reskey} = $resopts;
     }
 }
 
@@ -1342,6 +1356,7 @@
     my $ret = "";
     my $ret_js  = "";
     my $ret_css = "";
+    my %libs    = (); ## pseudo files.
     my $do_concat = $LJ::IS_SSL ? $LJ::CONCAT_RES_SSL : $LJ::CONCAT_RES;
 
     # all conditions must be complete here
@@ -1459,18 +1474,6 @@
            </script>
         };
 
-        ## Filter included res.
-        ## if resource is a part of a common set, skip it here
-        ## and add to page inside the set.
-        @LJ::NEEDED_RES = grep {
-                    ## check common JS sources.
-                    if ($LJ::STRICTLY_INCLUDED_JS_H{$_}){
-                        $LJ::NEEDED_RES{include_common_js} = 1;
-                        0; ## include this file as a part of common sources set.
-                    } else {
-                        1; ## include them as is.
-                    }
-                } @LJ::NEEDED_RES;
     } ## / unless $only_needed
 
     my $host = LJ::Request->header_in("Host");
@@ -1512,8 +1515,7 @@
             } else if ( lj_master_user > 0 && lj_master_user !== lj_user ) {
                 window.location = "${LJ::SITEROOT}/misc/get_domain_session.bml?return=$curl";
             }
-        </script>
-        |;
+        </script>\n|;
     }
 
     my $now = time();
@@ -1539,31 +1541,25 @@
     };
 
 
-    ## Some of basic JS sources are widely used.
-    ## Include all even required only one of them.
-    if ($LJ::NEEDED_RES{include_common_js}){
-        foreach my $js (@LJ::STRICTLY_INCLUDED_JS){
-            my $mtime = _file_modtime("js/$js", $now);
-            $add->(common_js => $js, $mtime); ## without "js" prefix
-        }
-    }
-
     foreach my $key (@LJ::NEEDED_RES) {
         my $path;
-        my $mtime = _file_modtime($key, $now);
-        $path = $key;
+        my $mtime;
+        my $library;
 
-        # if we want to also include a local version of this file, include that too
-        if (@LJ::USE_LOCAL_RES) {
-            if (grep { lc $_ eq lc $key } @LJ::USE_LOCAL_RES) {
-                my $inc = $key;
-                $inc =~ s/(\w+)\.(\w+)$/$1-local.$2/;
-                LJ::need_res($inc);
+        ## for libraries check mtime of all files
+        if (my $library_files = $LJ::JS_SOURCES_MAP{$key}){
+            $library = $key;
+            $libs{$library} = 1;
+            foreach my $file (@$library_files){ 
+                my $lmtime = _file_modtime($key, $now);
+                $mtime = $lmtime if $lmtime > $mtime;
             }
         }
 
+        $path = $key;
+
         if ($path =~ m!^js/(.+)!) {
-            $add->('js', $1, $mtime, $LJ::NEEDED_RES{$key});
+            $add->("js$library", $1, $mtime, $LJ::NEEDED_RES{$key} || {});
         }
         elsif ($path =~ /\.css$/ && $path =~ m!^(w?)stc/(.+)!) {
             $add->("${1}stccss", $2, $mtime, $LJ::NEEDED_RES{$key});
@@ -1619,14 +1615,20 @@
     ##  (C) http://code.google.com/speed/page-speed/
     ##
     $ret .= $ret_css unless $opts->{only_js};
-    $tags->("stccss",  "<link rel=\"stylesheet\" type=\"text/css\" href=\"$statprefix/___\" ##/>");
-    $tags->("wstccss", "<link rel=\"stylesheet\" type=\"text/css\" href=\"$wstatprefix/___\" ##/>");
+    $tags->("stccss",  "<link rel=\"stylesheet\" type=\"text/css\" href=\"$statprefix/___\" ##/>")  unless $opts->{only_js};
+    $tags->("wstccss", "<link rel=\"stylesheet\" type=\"text/css\" href=\"$wstatprefix/___\" ##/>") unless $opts->{only_js};
     
-    $ret .= $ret_js unless $opts->{only_css};
-    $tags->("common_js", "<script type=\"text/javascript\" src=\"$jsprefix/___\"></script>");
-    $tags->("js",      "<script type=\"text/javascript\" src=\"$jsprefix/___\"></script>");
-    $tags->("stcjs",   "<script type=\"text/javascript\" src=\"$statprefix/___\"></script>");
-    $tags->("wstcjs",  "<script type=\"text/javascript\" src=\"$wstatprefix/___\"></script>");
+    unless ($opts->{only_css}){
+        $ret .= $ret_js;
+        foreach my $library (@LJ::JS_SOURCES_ORDER){ ## add libraries in strict order
+            next unless $libs{$library};
+            $tags->("js$library", "<script type=\"text/javascript\" src=\"$jsprefix/___\"></script>");
+        }
+        $tags->("common_js", "<script type=\"text/javascript\" src=\"$jsprefix/___\"></script>")  unless $opts->{only_css};
+        $tags->("js",      "<script type=\"text/javascript\" src=\"$jsprefix/___\"></script>")    unless $opts->{only_css};
+        $tags->("stcjs",   "<script type=\"text/javascript\" src=\"$statprefix/___\"></script>")  unless $opts->{only_css};
+        $tags->("wstcjs",  "<script type=\"text/javascript\" src=\"$wstatprefix/___\"></script>") unless $opts->{only_css};
+    }
 
     return $ret if $only_needed;
 

Tags: livejournal, pl, vad, vadvs
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments