Avatar of lexo
lexo

asked on 

Best practice to build a very large dynamic menu in coldfusion

What is the best practice to create a dynamic menu using coldfusion and javascript.  I want the menu to call the db minimally and the menu must be able to branch out to several levels with onClick events.  The menu must load fast as there will be several thousand pages, so I am thinking that maybe the menu query results get stored in a session value? I'm not sure if this is a good technique.  A link to a tutorial will suffice to answer this question.
Web Servers

Avatar of undefined
Last Comment
lexo
Avatar of dgrafx
dgrafx
Flag of United States of America image

I don't have a link to a tutorial but just create the session var like:
<cfif Not StructKeyExists(session,"menuList")>
<cfquery ... >
select ...
</cfquery>
<cfsavecontent variable="menuContent">
put your code that builds menu inside here
</cfsavecontent>
<cflock scope="session" type="exclusive" timeout="15">
<cfset session.menuList=menuContent>
</cflock>
</cfif>

#session.menuList#
Avatar of lexo
lexo

ASKER

Do you think that saving the data in a session variable like this is the best/fastest way to go?
Avatar of dgrafx
dgrafx
Flag of United States of America image

much faster than not putting it in a session.
and as far as best practices -
if menu is always the same - meaning that one user sees the same menu as everyone else then I'd put it in the application scope
but if you have a members area (for ex) that is determined by a users login then it would need to be in a session
you'd setup a default menu to start and when and if user logs in then set their "session menu" is reset to whatever is applicable
 
Avatar of lexo
lexo

ASKER

Everyone would see the same menu, it is a public site.

Is this how it would be done?

<cfif Not StructKeyExists(application,"menuList")>
<cfquery ... >
select ...
</cfquery>
<cfsavecontent variable="menuContent">
put your code that builds menu inside here
</cfsavecontent>
<cflock scope="application" type="exclusive" timeout="15">
<cfset application.menuList=menuContent>
</cflock>
</cfif>

#application.menuList#
ASKER CERTIFIED SOLUTION
Avatar of dgrafx
dgrafx
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of lexo
lexo

ASKER

Thank you.
Web Servers
Web Servers

A web server refers to the software that helps to deliver web content that can be accessed either through the Internet or through an intranet. The primary function of a web server is to store, process and deliver web pages to clients. The communication between client and server takes place using the Hypertext Transfer Protocol (HTTP). The most common use of web servers is to host websites, but there are other uses such as gaming, data storage, running enterprise applications, handling email, FTP, etc.

33K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo