Optimize SUI core to load script with disableCache option

This commit is contained in:
Max 2024-07-27 10:28:17 +08:00
parent 99a77fdd8e
commit 5050443e63
2 changed files with 7 additions and 4 deletions

View file

@ -277,7 +277,7 @@ func (parser *TemplateParser) parseElementComponent(sel *goquery.Selection) {
if parser.option.Imports != nil {
if route, has := parser.option.Imports[com]; has {
file := filepath.Join(string(os.PathSeparator), "public", parser.option.Root, route)
script, err = LoadScript(file)
script, err = LoadScript(file, parser.disableCache())
if err != nil {
parser.errors = append(parser.errors, err)
setError(sel, err)

View file

@ -52,11 +52,14 @@ func scriptWriter() {
}
// LoadScript load the script
func LoadScript(file string) (*Script, error) {
func LoadScript(file string, disableCache ...bool) (*Script, error) {
base := strings.TrimSuffix(strings.TrimSuffix(file, ".sui"), ".jit")
if script, has := Scripts[base]; has {
return script, nil
// LOAD FROM CACHE
if disableCache == nil || !disableCache[0] {
if script, has := Scripts[base]; has {
return script, nil
}
}
file = base + ".ts"