View Full Version : Application object, how many values can/should it store?
Dodger
10-26-2002, 06:10 PM
With values the length of RGB color codes and URL's etc. (basic settings of a site)
TIA.
dominicall
10-31-2002, 10:53 AM
Hi Dodger
If you need to store constants that will be used across the site, rather than use up server resource by storing the info in Application variables the better way to do it is to create a 'globals.asp' page for inclusion on every page. I've attached mine (edited) as an example.
All you need to do is put this line into everypage and then you can call the information anytime you need.
<!-- #include virtual="/yourincludesdirectory/global.asp" -->
This is partcularly useful if you've got bits of code that you always use. For example, with a spacer image (transparent pixel), the boring way to keep entering the code again and again is...
<img src="/images/general/transparent.gif">
I keep the location of the file in my global.asp page and just type...
<img src="<%=transgif%>">
Does look much of a difference now but does make a heck of a difference when you use it a lot.
Hope this helps
Dominic :D
Dodger
11-16-2002, 07:20 PM
Thanks dominicall,
But, doesn't it take up a lot of memory having to load the whole page of constants on every page?
Also, is there an easy way to modify those constants via code?
Kind Regards, Dodger.
dominicall
11-16-2002, 07:38 PM
Nope - my globals file is just under 2K - and it's loaded with the page as an include so doesn't take much memory at all...
You can't programatically change the values in the constants in the globals file, but if you temporarily need to use a different value for the constant then you just give it a different value in your page... i.e.
lets say you have a constant that defines the colour for table headings as belowConst TABLE_HEAD="#990000"
but for one particular page you need to use a different colour then all you need to do is redefine the value in that page, like below... TABLE_HEAD = "#999000"
Also, it means that you only need to load the constants when you need to - so if you have a page that doesn't need the constants then you don't need to include the file which reduces the memory overhead - you'd lose that flexibility if you were storing the 'constants' in the application object.
Hope that helps.
Dominic :D
Dodger
11-16-2002, 07:44 PM
But all the constants are loaded locally in the clients browser, but not so with the application object?
dominicall
11-16-2002, 07:49 PM
Nope - the constants are ASP constants that stay on the server - just like variables... you can even make multiple changes in any page - so if your constant for TABLE_HEAD is "#990000" and you want it to be different on another page you can do the following...
TABLE_HEAD = "#999000"
... then your table here....
TABLE_HEAD = "#000999"
... and another table here with a different table heading color ....
TABLE_HEAD = "#ffffff"When the page is initially loaded the constants are instantiated server side and can be changed, just like any variable.
If you don't need them then just don't include the constants file.
Dominic :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.