Skip to content

Commit 31360f0

Browse files
committed
Improve header load times
1 parent 23c08d8 commit 31360f0

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

src/templates/Maintenance.phtml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace BNETDocs\Templates;
33
$title = 'Maintenance';
44
$description = $this->getContext()->message;
5+
$_header_maintenance = true;
56
require('./header.inc.phtml'); ?>
67
<div class="container">
78
<div class="alert alert-danger" role="alert">

src/templates/footer.inc.phtml

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ and/or other countries.
2020
</p>
2121
</div>
2222
</footer>
23-
<script type="text/javascript" src="<?=Common::relativeUrlToAbsolute('/a/datatables.min.js' . $_unique_asset)?>" async><![CDATA[]]></script>
23+
<script type="text/javascript" src="<?=Common::relativeUrlToAbsolute('/a/datatables.min.js' . ($_unique_asset ?? ''))?>" async><![CDATA[]]></script>
2424
<?=Logger::getTimingFooter()?>
2525
<?php if (Common::$config->analytics->cloudflare) { ?>
2626
<!-- Cloudflare Web Analytics --><script defer src="https://static.cloudflareinsights.com/beacon.min.js" data-cf-beacon='{"token":<?=json_encode(Common::$config->analytics->cloudflare)?>}'></script><!-- End Cloudflare Web Analytics -->
2727
<?php } ?>
2828

29-
<script src="/a/jquery-3.4.1.slim.min.js" type="text/javascript" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"><![CDATA[]]></script>
30-
<script src="/a/popper-1.16.0.min.js" type="text/javascript" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"><![CDATA[]]></script>
31-
<script src="/a/bootstrap-4.4.1.min.js" type="text/javascript" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"><![CDATA[]]></script>
32-
<script src="/a/datatables.min.js" type="text/javascript" crossorigin="anonymous" charset="utf8"><![CDATA[]]></script>
33-
<script src="/a/highlight/highlight.min.js" type="text/javascript" crossorigin="anonymous" charset="utf8"><![CDATA[]]></script>
29+
<script src="<?=Common::relativeUrlToAbsolute('/a/jquery-3.4.1.slim.min.js' . ($_unique_asset ?? ''))?>" type="text/javascript" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"><![CDATA[]]></script>
30+
<script src="<?=Common::relativeUrlToAbsolute('/a/popper-1.16.0.min.js' . ($_unique_asset ?? ''))?>" type="text/javascript" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"><![CDATA[]]></script>
31+
<script src="<?=Common::relativeUrlToAbsolute('/a/bootstrap-4.4.1.min.js' . ($_unique_asset ?? ''))?>" type="text/javascript" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"><![CDATA[]]></script>
32+
<script src="<?=Common::relativeUrlToAbsolute('/a/datatables.min.js' . ($_unique_asset ?? ''))?>" type="text/javascript" crossorigin="anonymous" charset="utf8"><![CDATA[]]></script>
33+
<script src="<?=Common::relativeUrlToAbsolute('/a/highlight/highlight.min.js' . ($_unique_asset ?? ''))?>" type="text/javascript" crossorigin="anonymous" charset="utf8"><![CDATA[]]></script>
3434
<script type="text/javascript">$(document).ready(function(){hljs.highlightAll()});</script>
35-
<script src="/a/moment-2.24.0.min.js" type="text/javascript" crossorigin="anonymous" charset="utf8"><![CDATA[]]></script>
36-
<?php if (!empty($_footer_script)) { echo $_footer_script; } ?>
35+
<script src="<?=Common::relativeUrlToAbsolute('/a/moment-2.24.0.min.js' . ($_unique_asset ?? ''))?>" type="text/javascript" crossorigin="anonymous" charset="utf8"><![CDATA[]]></script>
36+
<?=(isset($_footer_script) && !empty($_footer_script) ? $_footer_script : '')?>
3737
</body></html>

src/templates/header.inc.phtml

+21-18
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,20 @@ $_header_nav = [
5252
]],
5353
['label' => 'News', 'dropdown' => [
5454
['label' => 'All News', 'url' => '/news', 'class' => 'text-info'],
55-
['label' => '-'],
56-
['label' => 'Create News Post', 'url' => '/news/create', 'class' => 'text-success', 'acl' => User::OPTION_ACL_NEWS_CREATE],
5755
['label' => '-', 'acl' => User::OPTION_ACL_NEWS_CREATE],
56+
['label' => 'Create News Post', 'url' => '/news/create', 'class' => 'text-success', 'acl' => User::OPTION_ACL_NEWS_CREATE],
5857
['label' => '', 'recent_news' => true],
5958
]],
6059
['label' => 'Documents', 'dropdown' => [
6160
['label' => 'All Documents', 'url' => '/document/index', 'class' => 'text-info'],
62-
['label' => '-'],
63-
['label' => 'Create Document', 'url' => '/document/create', 'class' => 'text-success', 'acl' => User::OPTION_ACL_DOCUMENT_CREATE],
6461
['label' => '-', 'acl' => User::OPTION_ACL_DOCUMENT_CREATE],
62+
['label' => 'Create Document', 'url' => '/document/create', 'class' => 'text-success', 'acl' => User::OPTION_ACL_DOCUMENT_CREATE],
6563
['label' => '', 'recent_documents' => true],
6664
]],
6765
['label' => 'Packets', 'dropdown' => [
6866
['label' => 'All Packets', 'url' => '/packet/index', 'class' => 'text-info'],
69-
['label' => '-'],
70-
['label' => 'Create Packet', 'url' => '/packet/create', 'class' => 'text-success', 'acl' => User::OPTION_ACL_PACKET_CREATE],
7167
['label' => '-', 'acl' => User::OPTION_ACL_PACKET_CREATE],
68+
['label' => 'Create Packet', 'url' => '/packet/create', 'class' => 'text-success', 'acl' => User::OPTION_ACL_PACKET_CREATE],
7269
['label' => '', 'recent_packets' => true],
7370
]],
7471
['label' => 'Admin', 'acl' => User::OPTION_ACL_SERVER_CREATE | User::OPTION_ACL_EVENT_LOG_VIEW, 'class' => 'text-danger', 'dropdown' => [
@@ -113,8 +110,9 @@ function _header_nav_html($nav)
113110
$class = $item['class'] ?? '';
114111
if (!empty($class)) $class = ' ' . $class;
115112

116-
if (isset($item['recent_documents']) && $item['recent_documents'])
113+
if (isset($item['recent_documents']) && $item['recent_documents'] && isset(Common::$database))
117114
{
115+
_line('<div class="dropdown-divider"></div>');
118116
_line('<div class="dropdown-header">Recently Edited Documents</div>');
119117
$recent_documents = Document::getDocumentsByLastEdited(10);
120118
$acl_doc_modify = (Authentication::$user && (Authentication::$user->getOptionsBitmask() & User::OPTION_ACL_DOCUMENT_MODIFY));
@@ -125,8 +123,9 @@ function _header_nav_html($nav)
125123
_line('<a class="dropdown-item%s" href="%s">%s</a>', $doc_class, $doc->getURI(), filter_var($doc->getTitle(), FILTER_SANITIZE_FULL_SPECIAL_CHARS));
126124
}
127125
}
128-
else if (isset($item['recent_news']) && $item['recent_news'])
126+
else if (isset($item['recent_news']) && $item['recent_news'] && isset(Common::$database))
129127
{
128+
_line('<div class="dropdown-divider"></div>');
130129
_line('<div class="dropdown-header">Recent News</div>');
131130
$recent_news = NewsPost::getNewsPostsByLastEdited(10);
132131
$acl_news_modify = (Authentication::$user && (Authentication::$user->getOptionsBitmask() & User::OPTION_ACL_NEWS_MODIFY));
@@ -137,8 +136,9 @@ function _header_nav_html($nav)
137136
_line('<a class="dropdown-item%s" href="%s">%s</a>', $news_class, $news->getURI(), filter_var($news->getTitle(), FILTER_SANITIZE_FULL_SPECIAL_CHARS));
138137
}
139138
}
140-
else if (isset($item['recent_packets']) && $item['recent_packets'])
139+
else if (isset($item['recent_packets']) && $item['recent_packets'] && isset(Common::$database))
141140
{
141+
_line('<div class="dropdown-divider"></div>');
142142
_line('<div class="dropdown-header">Recently Edited Packets</div>');
143143
$recent_packets = Packet::getPacketsByLastEdited(10);
144144
$acl_pkt_modify = (Authentication::$user && (Authentication::$user->getOptionsBitmask() & User::OPTION_ACL_PACKET_MODIFY));
@@ -175,18 +175,21 @@ function _header_nav_html($nav)
175175
_line('</ul>');
176176

177177
// Account
178-
if (!Authentication::$user)
178+
if (isset(Common::$database))
179179
{
180-
_line('<a class="btn btn-sm btn-outline-secondary my-2 my-sm-0" tabindex="-1" href="%s">Log in</a>', Common::relativeUrlToAbsolute('/user/login'));
181-
if (!Common::$config->bnetdocs->user_register_disabled)
180+
if (!Authentication::$user)
182181
{
183-
_line('<a class="btn btn-sm btn-outline-success my-2 my-sm-0 ml-2" tabindex="-2" href="%s">Register</a>', Common::relativeUrlToAbsolute('/user/register'));
182+
_line('<a class="btn btn-sm btn-outline-secondary my-2 my-sm-0" tabindex="-1" href="%s">Log in</a>', Common::relativeUrlToAbsolute('/user/login'));
183+
if (!Common::$config->bnetdocs->user_register_disabled)
184+
{
185+
_line('<a class="btn btn-sm btn-outline-success my-2 my-sm-0 ml-2" tabindex="-2" href="%s">Register</a>', Common::relativeUrlToAbsolute('/user/register'));
186+
}
187+
}
188+
else
189+
{
190+
_line('<span class="nav-item navbar-text mx-3"><a href="%s">%s</a></span>', Authentication::$user->getURI(), filter_var(Authentication::$user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS));
191+
_line('<a class="btn btn-sm btn-outline-danger my-2 my-sm-0" tabindex="-1" href="%s">Log out</a>', Common::relativeUrlToAbsolute('/user/logout'));
184192
}
185-
}
186-
else
187-
{
188-
_line('<span class="nav-item navbar-text mx-3"><a href="%s">%s</a></span>', Authentication::$user->getURI(), filter_var(Authentication::$user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS));
189-
_line('<a class="btn btn-sm btn-outline-danger my-2 my-sm-0" tabindex="-1" href="%s">Log out</a>', Common::relativeUrlToAbsolute('/user/logout'));
190193
}
191194

192195
// Collapsible Hamburger Menu (End)

0 commit comments

Comments
 (0)