Thank's Gus,
the idea is about caching js resources...
As you shurely have seen this is no more a question in Rnext ;-)
Main Topics
Browse All TopicsHello experts,
this is a knowlidge sharing topic.
All this stuff is solely my ideas nowhere else found on the net. So use it or let it (or give me points ;-))
First I have to describe the problem...
Before Rnext there are different places in design elements to place JavaScript code. The best place to deposit functions is the "JS Header" event on the form. This is not bad, but the big disadvantage is, that if you have some hundred lines of JavaScript code in this place the code is sent again and again to the browser with every browser request. No caching is done. Also if you have same functions on multiple forms you have to update all the forms when somethings is to change in JavaScript code. You can of corse place the code into the data/domino/html directory, but than you loose this fine design distribution and replication feature. You have to care about the JavaScript dataset names on the file system.
So wath would be the solution. I think, some sort of JavaScript libraries in the application databse.nsf.
For R5 this is solved easyly. Create a page. Call it best: "HeaderPage.js"
Mark in the page base property tab the checkbox: Treat page contents as HTML
Place now in this page all the JavaScript code you like to distribute to all forms.
Instead of placing the JavaScript code into forms "JS Header" events place this formula into forms "HTML Head Content" event:
"<SCRIPT LANGUAGE='JavaScript' SRC='/"+@Subset(@DbName;-1
That was all. Now you can maintain your JavaScript code in the page and use it in twenty or more forms...
Wath to do in R4.x?
No problems...
Define a form for maintaining JavaScript code. In this form define multiple fields to be able to split your JavaScript code into multiple JavaScript file attachements. When creating a document with this form, than should the text of every field containing javascript code start with this string: </SCRIPT>
If you like to maintain css in the same form, than the field content css should start with this string: </STYLE>
For every field on the form you will get one attachment into the document.
Place into forms Postsave event this code:
Sub Postsave(Source As Notesuidocument)
Dim doc As NotesDocument
Set doc = Source.Document
Forall i In doc.Items
If (i.Type = TEXT) Then
If (Ucase$(Left$(i.text,7)) = "<SCRIPT") Then
Call AttachIncludeFile(doc, i.Name & ".js" , i.Text, "</SCRIPT>")
Elseif (Ucase$(Left$(i.text,6)) = "<STYLE") Then
Call AttachIncludeFile(doc, i.Name & ".css" , i.Text, "</STYLE>")
End If
End If
End Forall
Call doc.Save(True,False)
End Sub
And this additional function:
Sub AttachIncludeFile(doc As NotesDocument, Byval IncludeName As String, Byval IncludeText As String, Byval IncludeEndTag As String)
Dim attName As String
Dim attText As String
Dim txtStart As Integer
Dim txtLen As Integer
Dim fileName As String
Dim fileNum As Integer
Dim rtitem As NotesRichTextItem
Dim object As NotesEmbeddedObject
Set rtitem = doc.GetFirstItem( "Body" )
If Not (rtitem Is Nothing) Then
If ( rtitem.Type = RICHTEXT ) Then
Set object = rtitem.GetEmbeddedObject( IncludeName)
If Not (object Is Nothing) Then
Call object.Remove
End If
End If
Else
Set rtitem = New NotesRichTextItem( doc, "Body" )
End If
txtStart = Instr(IncludeText,">")+1
txtLen = Instr(Ucase$(IncludeText),
If (txtStart > 0) Then
attText = Mid$(IncludeText, txtStart, txtLen)
fileNum = Freefile()
fileName = "C:\temp\" & IncludeName
Open fileName For Output As fileNum
Print #fileNum, attText
Close fileNum
Set object = rtitem.EmbedObject( EMBED_ATTACHMENT, "", fileName, fileName)
Kill fileName
End If
End Sub
The Postasave event and the AttachIncludeFile creates for every field either a js or a css attachment with the contenets of the field.
So you need only a view where you can lookup this document to access the attachments. As experts you know that this view has to be sorted in the first column.
When you have this, you can define in every form where you like to use this JavaScript attachments following formula:
path := "\'/"+@LeftBack(@Subset(@D
cssPref := "<link rel=stylesheet type=\'text/css\' href="+path;
jsPref := "<SCRIPT LANGUAGE=\'JavaScript\' SRC=" +path;
jsSuff := "\' ></SCRIPT>";
cssPref+"formcss.css\'>"+
jsPref+"navigate.js"+jsSuf
jsPref+"workflow.js"+jsSuf
jsPref+"all.js"+jsSuff
This example is showing how to acces the JavaScript attachments in a config.nsf database with a view FileLookup where the document is sorted as "JavaScriptFunctions"
From there are fetched four attachments to the form. Again, this is done only one time by the browser. Afterwards are the attachments fetched from browsers cache.
So, that is all.
I hope somebody can have any use of this.
Regards,
stamp
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Huh,
i have pasted the wrong snipppets for compares in the description! The "if" clauses contains the right content of field startings in R4.x solution: "<SCRIPT" and "<STYLE"
Also I have not checked if generaly this embbeding is neccessary. I use it only because it dose not hurt and it does garnties that this fields contain the right code;-)
PAQ'd the points were already at zero before my arrival. A request was made to award the points to snocross, but I'm not about to award a grade for an answer of "very interesting..." to a technical "question". Since there's good information in the "question" I am PAQing it.
SpideyMod
Community Support Moderator @Experts Exchange
Business Accounts
Answer for Membership
by: ghassan99Posted on 2001-05-29 at 00:50:16ID: 6131808
Hi Stamp,
For the first one, I have used the page in this way before but not for JS. As for the R4 method I have never seen it before.
Good work.
-Gus
PS For old browser support you need the @replacesubstring before the @subset to change the '\' to '/'