diff options
author | Yorhel <git@yorhel.nl> | 2020-05-29 09:51:09 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-05-29 09:51:11 +0200 |
commit | 3e2cacb826dc703b789d575c378f8dccb2dc95a6 (patch) | |
tree | f08801825809ae77ca847a016415f4a70fd714b4 /lib | |
parent | 475b01dcf589d34ea1b4b8ce22f4302605b251f5 (diff) |
JS: Split v2rw.js into plain.js and elm.js, only include JS files when necessary
The trace_log showed that the vast majority of pageviews do not need any
Elm modules at all, so we can save a lot by not loading them on the page.
Some pages (most notably: VN pages for not-logged-in visitors) do need
JS but don't load any Elm modules. I've added a 'js' flag to
HTML::framework_() to indicate that and ensure that plain.js is still
loaded.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNDB/Util/LayoutHTML.pm | 1 | ||||
-rw-r--r-- | lib/VNWeb/HTML.pm | 17 | ||||
-rw-r--r-- | lib/VNWeb/User/Lists.pm | 2 | ||||
-rw-r--r-- | lib/VNWeb/User/Notifications.pm | 2 | ||||
-rw-r--r-- | lib/VNWeb/VN/Page.pm | 2 |
5 files changed, 10 insertions, 14 deletions
diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm index 6bafbeda..a18542f8 100644 --- a/lib/VNDB/Util/LayoutHTML.pm +++ b/lib/VNDB/Util/LayoutHTML.pm @@ -35,7 +35,6 @@ sub htmlFooter { # %options => { pref_code => 1 } noscript id => 'pref_code', title => $self->authGetCode('/xml/prefs.xml'), '' if $o{pref_code} && $self->authInfo->{id}; script type => 'text/javascript', src => $self->{url_static}.'/f/vndb.js?'.$self->{version}, ''; - VNWeb::HTML::v2rwjs_() if $o{v2rwjs}; end 'body'; end 'html'; } diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm index 4231b3c1..25df6152 100644 --- a/lib/VNWeb/HTML.pm +++ b/lib/VNWeb/HTML.pm @@ -403,19 +403,11 @@ sub _hidden_msg_ { } -sub v2rwjs_ { # Also used by VNDB::Util::LayoutHTML. - script_ type => 'application/json', id => 'pagevars', sub { - # Escaping rules for a JSON <script> context are kinda weird, but more efficient than regular xml_escape(). - lit_(JSON::XS->new->canonical->encode(tuwf->req->{pagevars}) =~ s{</}{<\\/}rg =~ s/<!--/<\\u0021--/rg); - } if keys tuwf->req->{pagevars}->%*; - script_ type => 'application/javascript', src => config->{url_static}.'/f/v2rw.js?'.config->{version}, ''; -} - - # Options: # title => $title # index => 1/0, default 0 # feeds => 1/0 +# js => 1/0, set to 1 to ensure 'plain.js' is included on the page even if no elm_() modules are loaded. # search => $query # og => { opengraph metadata } # type => Database entry type (used for the main tabs & hidden message) @@ -441,7 +433,12 @@ sub framework_ { $cont->() unless $o{hiddenmsg} && _hidden_msg_ \%o; div_ id => 'footer', \&_footer_; }; - v2rwjs_; + script_ type => 'application/json', id => 'pagevars', sub { + # Escaping rules for a JSON <script> context are kinda weird, but more efficient than regular xml_escape(). + lit_(JSON::XS->new->canonical->encode(tuwf->req->{pagevars}) =~ s{</}{<\\/}rg =~ s/<!--/<\\u0021--/rg); + } if keys tuwf->req->{pagevars}->%*; + script_ type => 'application/javascript', src => config->{url_static}.'/f/elm.js?'.config->{version}, '' if tuwf->req->{pagevars}{elm}; + script_ type => 'application/javascript', src => config->{url_static}.'/f/plain.js?'.config->{version}, '' if $o{js} || tuwf->req->{pagevars}{elm}; } } } diff --git a/lib/VNWeb/User/Lists.pm b/lib/VNWeb/User/Lists.pm index dbfd0aea..bbc986d2 100644 --- a/lib/VNWeb/User/Lists.pm +++ b/lib/VNWeb/User/Lists.pm @@ -567,7 +567,7 @@ TUWF::get qr{/$RE{uid}/ulist}, sub { : $num_core_labels == 1 && $opt_labels->{5} ? 'wish' : 'list'; my $title = $own ? 'My list' : user_displayname($u)."'s list"; - framework_ title => $title, type => 'u', dbobj => $u, tab => $tab, + framework_ title => $title, type => 'u', dbobj => $u, tab => $tab, js => 1, $own ? ( pagevars => { uid => $u->{id}*1, labels => $LABELS->analyze->{keys}{labels}->coerce_for_json($labels), diff --git a/lib/VNWeb/User/Notifications.pm b/lib/VNWeb/User/Notifications.pm index 618328a4..59512f05 100644 --- a/lib/VNWeb/User/Notifications.pm +++ b/lib/VNWeb/User/Notifications.pm @@ -111,7 +111,7 @@ TUWF::get qr{/$RE{uid}/notifies}, sub { 'ORDER BY n.id', $opt->{r} ? 'DESC' : 'ASC' ); - framework_ title => 'My notifications', + framework_ title => 'My notifications', js => 1, sub { div_ class => 'mainbox', sub { h1_ 'My notifications'; diff --git a/lib/VNWeb/VN/Page.pm b/lib/VNWeb/VN/Page.pm index c3feac4a..d5c4b202 100644 --- a/lib/VNWeb/VN/Page.pm +++ b/lib/VNWeb/VN/Page.pm @@ -772,7 +772,7 @@ TUWF::get qr{/$RE{vrev}}, sub { enrich_item $v; - framework_ title => $v->{title}, index => !tuwf->capture('rev'), type => 'v', dbobj => $v, hiddenmsg => 1, og => og($v), + framework_ title => $v->{title}, index => !tuwf->capture('rev'), type => 'v', dbobj => $v, hiddenmsg => 1, js => 1, og => og($v), sub { rev_ $v if tuwf->capture('rev'); infobox_ $v; |