desertcrocodile has asked for the wisdom of the Perl Monks concerning the following question:

Hey guys, I'm currently making a web app in Mojolicious, but cannot figure out why the css stylesheets and js files I'm linking are not showing up. I've put them in the public directory in the same directory as my application.


This is the default layout I'm using:


<!doctype html><html> <head> <title>Main title</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11. +1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="/programcss.css"> <script type="text/javascript" src="listCollapse.js"></script> </head> <body><%== content %></body> </html>

I've tried all sorts of combinations of pathways to link to the files, but nothing seems to be working. I'm using Windows 7, and testing it in Chrome if that helps.


Here is the code for the app itself:


#!/usr/bin/env perl use Mojolicious::Lite; use File::Slurp; use Data::Dump qw(dump); use lib 'lib'; use webprogramsubs; # Documentation browser under "/perldoc" plugin 'PODRenderer'; get '/' => sub { my $c = shift; $c->render('contents'); }; app->start; __DATA__ @@ contents.html.ep <html> % layout 'default'; <body> <h1>a heading</h1> </body> </html>

Any advice would be much appreciated!

Replies are listed 'Best First'.
Re: Mojolicious - linking external css/js not working.
by neilwatson (Priest) on Jul 23, 2014 at 18:51 UTC

    Where is /programcss.css located? The directory 'public' is the document root for mojo apps.

    Neil Watson
    watson-wilson.ca

      OK I've just fixed it, it turns out the css file was in a folder in the public directory which I'd forgotten to reference, so I've just put it straight into the directory. Also the javascript I was trying to use was located inside the body, which I didn't realise as I was using the default layout. So I just moved the javascript to the default layout file.


      Phew, thanks for reminding me to check, my mind tends to go blank after coding for a whole day!

Re: Mojolicious - linking external css/js not working. ( taghelpers url_for / link_to / javascript / stylesheet )
by Anonymous Monk on Jul 23, 2014 at 21:24 UTC