### Optimize code

Considerations to optimize code.
UI Field Checks by using Futures
Instead of:
If txtUsername.Text = "" OR txtPassword.Text = "" Then ...
// Will make two requests
Use
Dim userF = txtUsername, passF = txtPassword.Text As Future
If userF.Value = "" Or passF.Value = "" Then ...
// Will make one request
Button Click instead of Button Event
Define a button and then use Button_Click in the B4J module instead of calling an event in the script section of the HTML file.
Define Sub Initialize for a Websocket Class Module
Ensure to define the Sub Initialize, even if not used.
If not done, the WebApp will crash when calling srvr.Start in the main module.
Example:
`Sub Class_Globals
Private ws As WebSocket
...
End Sub`
`Public Sub Initialize
End Sub`
`Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
ws = WebSocket1
...
End Sub`
Websocket reconnect
If disconnecting (close) from a B4J Server and reconnect using a new websocket, this websocket has to be initialized.
This is how it is designed.

Changed: , Category: WebApps, File: T6C277M2072.htm, ID: 2072