Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-13-2013, 02:37 AM
PinkMilk PinkMilk is offline
 
Join Date: May 2010
Location: Earth
Posts: 193
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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?
Reply With Quote
  #2  
Old 08-13-2013, 04:08 AM
Zachery's Avatar
Zachery Zachery is offline
 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 11,440
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 08-13-2013, 04:51 AM
PinkMilk PinkMilk is offline
 
Join Date: May 2010
Location: Earth
Posts: 193
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Zachery View Post
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.
Reply With Quote
  #4  
Old 08-13-2013, 09:42 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 View Post
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
Reply With Quote
  #5  
Old 08-13-2013, 02:36 PM
PinkMilk PinkMilk is offline
 
Join Date: May 2010
Location: Earth
Posts: 193
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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.
Reply With Quote
  #6  
Old 08-13-2013, 02:54 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by PinkMilk View Post
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]}");
    }

Reply With Quote
  #7  
Old 08-13-2013, 03:12 PM
PinkMilk PinkMilk is offline
 
Join Date: May 2010
Location: Earth
Posts: 193
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Also didn't work but I moved clientscript/vbulletin_css/ from unlink into preg match and is now.
Reply With Quote
  #8  
Old 08-13-2013, 03:13 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:46 PM.


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.06205 seconds
  • Memory Usage 2,245KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_code
  • (3)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete