You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2023-12-15 00:07:14

jhoux@zirrusone.com
Member
Registered: 2023-01-13
Posts: 14

When and How is CSS Minification Triggered?

It appears that the .min.css file is never regenerated during normal runtime use. sad

I created a plugin and added a CSS file.

In SuperAdmin debug mode, the CSS file loads with all other CSS files.

When logged in with another user (and at the anonymous login screen), the existing .min.css file loads, but it doesn't contain the CSS from my plugin CSS file.

Is there a manual process to trigger CSS minification?

Offline

#2 2023-12-15 00:34:59

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: When and How is CSS Minification Triggered?

When in debug mode, the minified CSS is never used.
Are you manually creating the minification?
How are you loading the CSS with your plugin?


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#3 2023-12-15 01:33:54

jhoux@zirrusone.com
Member
Registered: 2023-01-13
Posts: 14

Re: When and How is CSS Minification Triggered?

$PLUGIN_HOOKS[Hooks::ADD_CSS]['myplugin']        = 'myfile.css';

No, I'm not manually creating the minification.  Should I be?   That's why I posted the original question! smile

I presume for compatibility with plugins that bring their own CSS, GLPI would nee to automatically bundle CSS files and minify them.

Offline

#4 2023-12-15 02:10:51

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: When and How is CSS Minification Triggered?

GLPI doesn't minify anything during use. The only thing that minifies CSS is the CLI command "bin/console build:compile_scss" and the release build script. This only affects GLPI's own CSS. If a plugin developer wants to serve minified CSS, they need to generate that minified CSS themselves and make sure they refer to the minified CSS file path.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#5 2023-12-15 18:58:16

jhoux@zirrusone.com
Member
Registered: 2023-01-13
Posts: 14

Re: When and How is CSS Minification Triggered?

Hmm sad   I guess that explains why my plugin CSS code isn't packaged on the Login page.

I wrote CSS code to modify the Login page.  It works fine if I stick the code in one of the stock x.min.css files.

For the sake of clean architecture, I moved the CSS into a plugin .css file and used the plugin hook to add it.  Unfortunately the plugin .css URL is only linked in the HTML page header while logged in (doesn't load on anonymous/login page).

Is there a way to get either the plugin or the css file to load for anonymous page views?

Offline

#6 2023-12-15 22:16:12

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: When and How is CSS Minification Triggered?

Maybe by using the "display_login" hook to add a new <link> HTML element.

In the setup.php init function:
$PLUGIN_HOOKS['display_login']['myplugin'] = 'myplugin_display_login';
In the hooks.php file:
public function myplugin_display_login () {
   $plugin_path = Plugin::getWebDir('myplugin') . '/myfile.css';
   echo "<link rel='stylesheet' href='" . $plugin_path . "'>";
}
Obviously, replace "myplugin" with the internal name of your plugin.

No other plugin hooks are called on the login page currently.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#7 2023-12-15 22:39:34

jhoux@zirrusone.com
Member
Registered: 2023-01-13
Posts: 14

Re: When and How is CSS Minification Triggered?

Ok that makes sense.  I actually forgot that you can put a LINK tag for a stylesheet directly in HTML body. 

I used the display_login hook and it worked!! smile

Man its really nice when you get reminded of how simple HTML actually is.  We devs often get stuck in overengineered mindsets thanks to dealing with frameworks all the time -- too far removed from the metal. I have to know so many different frameworks, sometimes I think my head is going to blow up. big_smile

Thank you!

Offline

Board footer

Powered by FluxBB