Sorry we missed this one, most of the people who use Mojolicious follow the Perl tag.
To answer your question, use the content_for
helper to be able to place things where you want them.
Note that this also lets you put the imports at the top of your dependent template, or the bottom if you prefer!
I have an example below.
I would also recommend a separate template for standard JS imports that all pages need, though this is just for clarity.
#!/usr/bin/env perl
use Mojolicious::Lite;
any '/' => 'testscript';
app->start;
__DATA__
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
</head>
<body>
%= content
%= include 'common_js'
%= content_for 'js_imports'
</body>
</html>
@@ common_js.html.ep
<script src="js/jquery.min.js" type="text/javascript"></script>
@@ testscript.html.ep
%layout 'default';
%title 'Script Test';
% content_for 'js_imports' => begin
%= javascript begin
$(document).ready(function(){
alert('fails if jquery is not loaded');
});
% end
% end
<p>Main Page</p>
When you visit the '/' route, this produces
<!DOCTYPE html>
<html>
<head>
<title>Script Test</title>
</head>
<body>
<p>Main Page</p>
<script src="js/jquery.min.js" type="text/javascript"></script>
<script>//<![CDATA[
$(document).ready(function(){
alert('fails if jquery is not loaded');
});
//]]></script>
</body>
</html>