Style assets handling

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
Post Reply
User avatar
Arty
Registered User
Posts: 970
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Style assets handling

Post by Arty » Tue May 21, 2013 10:43 am

Currently template inheritance applies to templates and JavaScript files. Would it be cool to be able to apply it to everything? CSS, images, etc?

I suggest to create virtual directory for style resources instead of linking to style. For example, instead of styles/prosilver/theme/foo.png link to style.php/prosilver/theme/foo.png

What are advantages of doing that?
  • Template inheritance could be applied to all style files. Style authors won't need to copy css/images from parent style.
  • CSS could be parsed to include imported CSS files, reducing number of HTTP requests.
  • Links to mod-specific files would be integrated seamlessly, making it look like file is in style.
  • CSS and JS files could be parsed with template engine, allowing to:
    • Use conditional statements.
    • Use template hooks, allowing to add content to CSS/JS files.
    • Include language constants in JS files instead of putting them in overall_footer, reducing size of pages.
  • CSS and JS files could be minimized and cached
I'm not sure about structure of URLs. Adding style.php doesn't seem right. Any suggestions for cleaner solution? Path to file must be a part of URL path, something like whatever.php/assets/foo/bar, not part of query string to keep directory tree.
Formerly known as CyberAlien.

Free phpBB styles | Premium responsive XenForo styles

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: Style assets handling

Post by EXreaction » Tue May 21, 2013 2:39 pm

If this is done, I do not think it should be querying the database or loading any of the common phpBB libraries, like style.php used to do, for efficiency purposes.

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1731
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: Style assets handling

Post by DavidIQ » Tue May 21, 2013 2:40 pm

+1 for the style.php handler
I actually just did something like this at my job where I created a .net handler to route all images and stylesheets through it and the handler would take care of loading the proper image or stylesheet (multiple clients use the same code base). I had included the path as part of it. I'm not sure how well the style.php/prosilver/theme/foo.png format would work on a Window server though. For instance I had to go the route of content/?prosilver/theme/foo.png, which worked fine for IIS7 but not for IIS6. Ended up going with content/handler.ashx?prosilver/theme/foo.png.
Image

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: Style assets handling

Post by EXreaction » Tue May 21, 2013 2:56 pm

Have you ever tried Assetic Arty?
https://github.com/kriswallsmith/assetic

That may be a very good library to use for this stuff (it's already very widely used, it's included in Symfony).

User avatar
Arty
Registered User
Posts: 970
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: Style assets handling

Post by Arty » Tue May 21, 2013 3:03 pm

EXreaction wrote:If this is done, I do not think it should be querying the database or loading any of the common phpBB libraries, like style.php used to do, for efficiency purposes.
Database generally won't be needed because everything is supposed to be cached, but it will be needed for creating that cache.

Calculating actual location of file from styles tree would require loading styles tree. But that could be cached as well.
EXreaction wrote:Have you ever tried Assetic Arty?
https://github.com/kriswallsmith/assetic

That may be a very good library to use for this stuff (it's already very widely used, it's included in Symfony).
I've never heard of it. Will check it out.
Formerly known as CyberAlien.

Free phpBB styles | Premium responsive XenForo styles

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1731
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: Style assets handling

Post by DavidIQ » Tue May 21, 2013 3:14 pm

I assume it would look in the current style folder tree for the asset and if it doesn't find it there then look in the default style, i.e. prosilver?
Image

User avatar
Arty
Registered User
Posts: 970
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: Style assets handling

Post by Arty » Tue May 21, 2013 3:27 pm

DavidIQ wrote:I assume it would look in the current style folder tree for the asset and if it doesn't find it there then look in the default style, i.e. prosilver?
Something like that, but more complex. In 3.1 styles can have many parent styles, not just one + there are styles directories in mods.

For example:
Styles tree is this: prosilver -> progreen -> progreen_se
Installed mods: mod1 that has prosilver files, mod2 that has prosilver and progreen files.
URL of resource is: style.php/progreen_se/images/home.png

style.php will look for it in this order:
1. styles/progreen_se/images/home.png
... extensions don't have progreen_se, so skipping that
2. styles/progreen/images/home.png
3. ext/mod2/styles/progreen/images/home.png
... mod1 doesn't have progreen, so skipping that
4. styles/prosilver/images/home.png
5. ext/mod2/styles/prosilver/images/home.png
6. ext/mod1/styles/prosilver/images/home.png

and fetch whichever file is found first. Also it will cache files map so it won't do that search every time file is requested.
Formerly known as CyberAlien.

Free phpBB styles | Premium responsive XenForo styles

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: Style assets handling

Post by EXreaction » Mon Jul 22, 2013 6:43 pm

This is done now with INCLUDEJS/INCLUDECSS since Twig has been implemented.

Post Reply