Mojolicious::Plugin::CSSLoader - move css loading to the end of the document
version 0.08
In your startup:
startup
sub startup { my $self = shift; # do some Mojolicious stuff $self->plugin( 'CSSLoader' ); # more Mojolicious stuff }
In your template:
<% css_load('css_file.css') %>
This plugin adds a helper method to your web application:
This method requires at least one parameter: The path to the JavaScript file to load. An optional second parameter is the configuration. You can switch off the base for this CSS file this way:
# <link rel="stylesheet" href="$base/css_file.css"/> <% css_load('css_file.css') %> # <link rel="stylesheet" href="http://domain/css_file.css"/> <% css_load('http://domain/css_file.css', {no_base => 1}); # load css file only in Internet Explorer # <!-- [if IE]> <link rel="stylesheet" href="http://domain/css_file.css"/> <![endif] --> <% css_load('css_file.css', {ie => 1}); # load css file except in Internet Explorer # <!-- [if !IE]><!--> <link rel="stylesheet" href="http://domain/css_file.css"/> <!--<![endif] --> <% css_load('css_file.css', {ie => 0}); # load css file in Internet Explorer greater version 7 # <!-- [if gt IE 7]> <link rel="stylesheet" href="http://domain/css_file.css"/> <![endif] --> <% css_load('css_file.css', {ie => { '>' => 7 } }); # allowed ie settings: >, >=, <, <=, ==
When you use this module, a hook for after_render is installed. That hook inserts the <link> tag at the end of the <head> part or at the start of the document.
<link>
<head>
Called when registering the plugin. On creation, the plugin accepts a hashref to configure the plugin.
# load plugin, alerts are dismissable by default $self->plugin( 'CSSLoader' );
$self->plugin( 'CSSLoader' => { base => 'http://domain/css', # base for all CSS files media => 'screen', # media setting (default: none) });
This plugin uses the stash key __CSSLOADERFILES__, so you should avoid using this stash key for your own purposes.
__CSSLOADERFILES__
Renee Baecker <reneeb@cpan.org>
This software is Copyright (c) 2015 by Renee Baecker.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Mojolicious::Plugin::CSSLoader, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::CSSLoader
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::CSSLoader
For more information on module installation, please visit the detailed CPAN module installation guide.