Skip to main content
Known Participant
July 27, 2009
Question

link to css and javscript

  • July 27, 2009
  • 1 reply
  • 656 views

Hi,

I have my main folder with all my cfm files it also contains a folde called template with the header and footer for all the pages.

In every page I add the header

<cfinclude template="templates/header.cfm" />

and this contains relative links to my css and jquery

<link  rel="stylesheet" type="text/css" href="../css/main.css" />
<link  rel="stylesheet" type="text/css" href="../css/font.css" />
<link  rel="stylesheet" type="text/css" href="../css/forms.css" />
<script type="text/javascript" src="../scripts/jquery.js"></script>
<script src="../scripts/jquery.validate.js" type="text/javascript"></script>

The problem is I now have to have a subfolder with a few files in it. So my link changes to

<cfinclude template="../templates/header.cfm" />

and then the css and js is not included. I can get it working with absolute links (feels wrong to me) but i would like an elegant solution to get this working without duplicating the header.

Coldfusion or non serverside solutions much appreciated.

By the way...I thought you could just put a leading / to get the site root

<link  rel="stylesheet" type="text/css" href="/css/main.css" />
<link  rel="stylesheet" type="text/css" href="/css/font.css" />
<link  rel="stylesheet" type="text/css" href="/css/forms.css" />
<script type="text/javascript" src="/scripts/jquery.js"></script>
<script src="/scripts/jquery.validate.js" type="text/javascript"></script>

but this does not seem to work either.

    This topic has been closed for replies.

    1 reply

    Inspiring
    July 27, 2009

    Consider carefully when, and by whom, these two similar-looking but very-different declarations are evaluated:

    • The <cfinclude> directive is a ColdFusion directive that is resolved on the server by the Cold Fusion compiler.  It specifies the location of additional ColdFusion source-code files that the compiler will include into the source-code that it is processing.

    • HTML directives such as <link> and <script> are resolved on the client (end-user's) machine by the web-browser.  The web-browser hands this reference, as a URL, back to the server for resolution.  The browser has no idea where the HTML that is has been given "came from."