vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   css @import to <link> (https://vborg.vbsupport.ru/showthread.php?t=301109)

PinkMilk 08-13-2013 02:37 AM

css @import to <link>
 
when storing style sheets to file vBulletin uses @import:
Code:

@import url("clientscript/vbulletin_css/style-xxxx-xxx.css");
this has a negative impact on web page performance, is it some how possible to change this to link?
Code:

<link rel="stylesheet" type="text/css" href="style-xxxx-xxx.css" />

--- Update ---


I have found this in includes/adminfunctions_template.php which looks to be the code I need to edit:
PHP Code:

if (write_css_file($cssfilename$css))
                {
                    
$css "@import url(\"$cssfilename\");";
                } 

BUT

there is also this function that deletes the older css files:

PHP Code:

function delete_css_file($styleid$csscontents)
{
    if (
preg_match('#@import url\("(clientscript/vbulletin_css/style-\w{8}-0*' $styleid '\.css)"\);#siU'$csscontents$match))
    {
        
// attempt to delete old css file
        
@unlink("./$match[1]");
    }


so would need to change the preg_match regex for it to work with <link>, bit of an ask but can somebody be kind enough to rewrite the function?

Zachery 08-13-2013 04:08 AM

Uh, that is php code, not css code. I'm nearly positive vBulletin doesn't use an @import in the actual css rules. It uses a standard <link> tag, in the head.

PinkMilk 08-13-2013 04:51 AM

Quote:

Originally Posted by Zachery (Post 2438570)
Uh, that is php code, not css code. I'm nearly positive vBulletin doesn't use an @import in the actual css rules. It uses a standard <link> tag, in the head.

Under the vbulletin options > Style & Language Settings there is an option:
"Store CSS Stylesheets as Files?", if you check yes instead of the full css loading in page (see this sites source for example) you get something like this:

Code:

<style type="text/css" id="vbulletin_css">
/**
* vBulletin 3.8.5 CSS
* Style: 'foobar'; Style ID: 5
*/
@import url("clientscript/vbulletin_css/style-436ba35e-0005.css");
</style>

as you can see it uses @import, this is not the best option it is better to use <link> as explained in op.

The first php code snippet is what helps create this , each time you update your style a new css file is created and the function in op deletes the older stored css file.

kh99 08-13-2013 09:42 AM

Try replacing the preg line with:
Code:

if (preg_match('#<link rel="stylesheet" type="text/css" href="style-\w{8}-0*' . $styleid . '\.css" />#siU', $csscontents, $match))


Quote:

Originally Posted by Zachery (Post 2438570)
Uh, that is php code, not css code. I'm nearly positive vBulletin doesn't use an @import in the actual css rules. It uses a standard <link> tag, in the head.

I thought the same thing, but it turns out it is something that browsers recognize. http://stackoverflow.com/questions/1...why-use-import

PinkMilk 08-13-2013 02:36 PM

Quote:

Originally Posted by kh99 (Post 2438612)
Try replacing the preg line with:
Code:

if (preg_match('#<link rel="stylesheet" type="text/css" href="style-\w{8}-0*' . $styleid . '\.css" />#siU', $csscontents, $match))
I thought the same thing, but it turns out it is something that browsers recognize. http://stackoverflow.com/questions/1...why-use-import

Thanks but didn't work, I have the <link> format working great its just the deleting of the older stylesheet, guess I will have to just remember to clean that folder out from time to time.

kh99 08-13-2013 02:54 PM

Quote:

Originally Posted by PinkMilk (Post 2438656)
Thanks but didn't work, I have the <link> format working great its just the deleting of the older stylesheet, guess I will have to just remember to clean that folder out from time to time.


Oh right - I got the pattern to match but forgot that it needs parens around the matched part to use in the unlink call. If you want to try again, you could try this:

PHP Code:

function delete_css_file($styleid$csscontents)
{
if (
preg_match('#<link rel="stylesheet" type="text/css" href="(style-\w{8}-0*' $styleid '\.css)" />#siU'$csscontents$match))
    {
        
// attempt to delete old css file
        
@unlink("./clientscript/vbulletin_css/{$match[1]}");
    }



PinkMilk 08-13-2013 03:12 PM

Also didn't work but I moved clientscript/vbulletin_css/ from unlink into preg match and is now.

kh99 08-13-2013 03:13 PM

I was just wondering if your <link> tag had the path in the file name or not. I guess it does.


All times are GMT. The time now is 07:54 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01032 seconds
  • Memory Usage 1,744KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (3)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete