Skip to main content
Participant
April 19, 2012
Question

code snippets

  • April 19, 2012
  • 2 replies
  • 524 views

I would like to store several different code snippets on one page.  I will have an ajax window pop up and depending on the action that called the window it will draw a specific snippet from the set of code blocks.  I'm not sure how to go about this.  I want to be sure that only the block of code needed is executed as there will be over 100 code snippets and each will contain a different database query and display different content.

Does anyone know how I might best attack this?  I was thinking of using  <cfscript> and naming each a different function but I want this file stored seperately.  I'm afraid that if I include the file it will make the page load hard. 

A side note, I am hosting 3rd party and I don't have access to the cf administrator so I think that rules out creating a .cfc.

Thanks for any hints on this.

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    April 19, 2012

    polarbear19971997 wrote:

    ... store several different code snippets on one page.

    ... have an ajax window pop up and depending on the action that called the window it will draw a specific snippet from the set of code blocks.

    ... only the block of code needed is executed...

    ... there will be over 100 code snippets and each will contain a different database query and display different content.

    Translate what you call code snippets or code blocks  into functions in a component. However, not just one component for all 100 functions!

    Find a logical way to subdivide the whole into components, and for grouping the functions under each component. Aim for 10 to 15 components, with an average of 6 to 10 functions per components.

    You can easily oversee your code today, as everything is still fresh in your mind. However, you have to think about future maintenance. The logic of certain code decisions may become blurred with time. In general, the more the number of functions in a component, the more likely will be the degree of vagueness in future. In this way, a component with 20 functions will be more difficult to maintain than one with 7.

    Inspiring
    April 19, 2012

    I'm not sure why you can't create a cfc, but in any event you can make all your snippets functions and put them in a .cfm file.  You then cfinclude that file as required.

    I wouldn't worry about the page load.  You have to write this code somewhere.