Jump to:

23371 Posts in 18161 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » CMS references css files differently on production server

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 522 Views
  • mycrazydream
    Avatar
    Community Member
    6 Posts

    CMS references css files differently on production server Link to this post

    For some reason the CMS on our production server does not load the main, content panel correctly. When you first load up Pages, it is blank. Using Firebug, I noticed that it was loading many files via ajax in production that it wasn't on our development server.

    Besides a ping, Dev just loads these two:

    /admin/pages/treeview
    /admin/pages/listview

    I then realized it is doing so because the <link> tags that bring in the CSS are referencing the files differently in production. Basically, they are missing the first forward slash in the href path, and so they are not loading the CSS files.

    For example, this is wrong:

    <link rel="stylesheet" type="text/css" href="framework/admin/thirdparty/jquery-notice/jquery.notice.css?m=1340880397" />
    <link rel="stylesheet" type="text/css" href="framework/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css?m=1340880400" />

    This is right:

    <link rel="stylesheet" type="text/css" href="/framework/admin/thirdparty/jquery-notice/jquery.notice.css?m=1340880397" />
    <link rel="stylesheet" type="text/css" href="/framework/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css?m=1340880400" />

    Now, the really strange thing is that for some reason the following code causes it to load the files correctly, and I see no reason that it should. In the course of investigation I added this to the bottom of SSViewer::process():

    preg_match_all('/<link.+>/',$output,$m);
    if(count($m[0])){
    foreach($m as &$a){
    print_r(array_map("htmlentities",$a));
    }
    }

    I've attached two images. The first shows the problem - a blank panel. The second shows the panel loading the data correctly, with the debugging output. Makes no sense to me, so I was hoping to use the forum as a sounding board. Any ideas?

    Attached Files
  • mycrazydream
    Avatar
    Community Member
    6 Posts

    Re: CMS references css files differently on production server Link to this post

    In fact, outputting any character before the DOCTYPE

    .<!DOCTYPE html>

    causes it to reference the css files correctly, and thus load correctly.

  • mycrazydream
    Avatar
    Community Member
    6 Posts

    Re: CMS references css files differently on production server Link to this post

    Maybe if I put it another way, someone can see where the problem lies...

    In Requirements::includeInHTML(), this builds the <head> css file links

    foreach(array_diff_key($this->css,$this->blocked) as $file => $params) {                
                $path = $this->path_for_file($file);
    //this always looks correct, starting "/framework/..."
                if($path) {
                   $media = (isset($params['media']) && !empty($params['media'])) ? " media=\"{$params['media']}\"" : "";
                   $requirements .= "<link rel=\"stylesheet\" type=\"text/css\"{$media} href=\"$path\" />\n";
                }
             }

    But when I view the source after the page is built, the link's href is as follows:

    <link rel="stylesheet" type="text/css" href="framework/admin/thirdparty/jquery-notice/jquery.notice.css?m=1342411329" />

    How the hell does it start "framework" now without the forward-slash??? ANd how does screwing up the doctype by adding a character before it fix the path? That shouldn't be able to change the markup??? The browser doesn't seem to matter, tested so far in Firefox, Safari, Chrome.

    522 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.