Plugin CSS added to the main list?

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
Plugin CSS added to the main list?
« on October 30th, 2011, 04:32 AM »
So my plugin uses a wecss file to add a style to an element. since it just extends a base class[1], I could have easily applied the class to the element in the markup. But I had to go the long route[2] and use the awesome parser.

Here's part of what tripped me. add_plugin_css_file('file', true); adds a stylesheet to the head. But, as I found out, it would get rid of the style, probably because the base class wasn't found and left the style empty so it got deleted.So it seems inheritance works within the same file, not all of them.

In the end I actually made some hackish code to do what I want.It doesn't seem to be very efficient, though. :/

Code: [Select]
$context['css_main_files'][] = 'file';
$context['skin_folders'][] = array($context['plugins_dir']['plugin_id'] . '/', 'plugin_id_');
$settings['plugin_id_url'] = $context['plugins_dir']['plugin_id'];
 1. base: .foldable, and that's it, really. The file literally only defines that one style. :o
 2. Which ended up taking up half the day, plus my mouse scroll wheel started acting up last night, which makes browsing through code files a PITA.  :^^;:
A confident man keeps quiet.whereas a frightened man keeps talking, hiding his fear.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin CSS added to the main list?
« Reply #1, on October 30th, 2011, 04:36 AM »
Hmm, this does solve one issue that Nao mentioned to me, that plugin CSS files weren't integrated into main CSS files (which I thought was a bad idea generally, on the basis that different plugins firing different files meant you might generate a great many cached files without realising it) - though it would solve the problem I had about top level menu items not being extensible without work.

However, I can see the logic of what you're doing. Define "not very efficient". What this will cause to happen is a test made every page load to the CSS files being requested, to see if they have been defined or not, but it'll be for all the files in the current stack (if I understand it correctly)
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
Re: Plugin CSS added to the main list?
« Reply #2, on October 30th, 2011, 04:46 AM »
You're still up? O_o

Not very efficient: It loops through all the defined skin folders (one on the default skin, haven't tried on children) and within that loop, each file and its variant. The code above added three: main, firefox, member. Although it does skip the process if the cache is already built as you've noted. So I guess it's still efficient enough!

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Plugin CSS added to the main list?
« Reply #3, on October 30th, 2011, 10:12 AM »
It scares me a little that you're discussing stuff related to code I wrote entirely, but that I've totally lost grasp on because plugin support was added onto it... :^^;:

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin CSS added to the main list?
« Reply #4, on October 30th, 2011, 04:33 PM »
OK, the issue as was originally pointed out is that calling add_plugin_css_file will create a new file in the cache, rather than integrate it into the main single CSS file.

There are both good and bad points to this, and it sort of bothers me that it would be left to plugin authors. If you add it on every page without fail, e.g. there is a bandwidth benefit yo getting it into every single CSS file that's cached, with the downside is that cache evaluation goes up every page as extra paths are evaluated.

On the other hand, if you indicate an extra file to be loaded, that goes through the minifier and is then essentially cached with a long life time on it, but it is a second HTTP request. Now, that might not be best, but I'd argue it might be preferable to the hordes of cached CSS files.

Right now, for example, I as a logged in Chrome user get chrome-member built. It's also possible that I might have triggered the guest version for Chrome also to have been cached. Then I add a style sheet that appears to both guests and members, but not every page.

Now I have chrome-guest, chrome-member, plugin-chrome-member, plugin-chrome-guest. Now multiply that by permutations based on browser sheets, and plugin combinations that might emerge. 3 plugins with their own stylesheets that may or may not be loaded at the same time gives you 8 permutations of CSS, multiplied by guest/member, multiplied by browser branches.

I figured it wasn't worth the effort and that it was better not to go down that road at all.

Nao

  • Dadman with a boy
  • Posts: 16,079