Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
External JS and CSS Files
#1
Hello,

I use Bootstrap for my IntraWeb project and there are many css and js files which using in each page (same and differ of each pages).
Now I use AddBodyScriptFile and ContentFiles to add them in my each form. It's work, if build with SA Indy (.exe) but I switch to build with ISAPI (.dll) and test it on IIS. I found AddBodyScriptFile and ContentFiles not working in this case. Below is result

example my css and js link when Run Web App with SA Indy (.exe) --> OK

<link href="/assets/mycss.cssrel="stylesheettype="text/css"/>

<script src="/assets/myjs.min.js"></script>


but this is example my css and js link when Run Web App with ISAPI (.dll) --> not working

<link href="/myIWProject.dll/assets/mycss.cssrel="stylesheettype="text/css"/>

<script src="/myIWProject.dll/assets/myjs.min.js"></script>

--------
The Problem : when Run Web App with ISAPI (.dll) in path of both CSS and JS have my dll name together ( this case is --> /myIWProject.dll on the file path).
How to cancel this name/path(/myIWProject.dll) or 
Which way I should to add link(css) and script(js) tag for css and js path in my each Delphi form (Each form may not reference the same css or js.)

Thank you.
Reply
#2
If "/myIWProject.dll" is normal standard path of ISAPI please advice me for declare css or js file path to me for work fine on both SA and ISAPI.

such I want to refer to 
- CSS files : "assets/mycss.css" in folder wwwroot
- JS files : "assets/myjs.min.js" in folder wwwroot

How should I give string argument to AddBodyScriptFile and ContentFiles?
Now I using :

ContentFiles.Add('/assets/mycss.css');
PageContext.AddBodyScriptFile('/assets/myjs.min.js');

Them work fine for the SA but doesn't work for the ISAPI.

Thanks
Reply
#3
(04-03-2023, 06:11 AM)baxing Wrote: If "/myIWProject.dll" is normal standard path of ISAPI please advice me for declare css or js file path to me for work fine on both SA and ISAPI.

such I want to refer to 
- CSS files : "assets/mycss.css" in folder wwwroot
- JS files : "assets/myjs.min.js" in folder wwwroot

How should I give string argument to AddBodyScriptFile and ContentFiles?
Now I using :

ContentFiles.Add('/assets/mycss.css');
PageContext.AddBodyScriptFile('/assets/myjs.min.js');

Them work fine for the SA but doesn't work for the ISAPI.

Thanks


Hi

Use the ServerController URLbase property:
cssfile := IWServerController.URLBase+'assets/mycss.css';

------
URLBase: string; [Published, Read/Write]

URLBase is the common prefix found while navigating inside a given website is known as the base URL. The URLBase is concatenated with the server's root URL to form the application URL. Example: server URL is www.yourserver.com and application URLBase is /myapp/, the application root url will be http(s)://www.yourserver.com/mypp/

https://docs.atozed.com/docs.dll/classes...rBase.html
Reply
#4
Hi,

Thank you very much, I tested it and it works.

And if it's the case that I want to link to the css and js files inside the html file, how should I set the path?

<link href="dist/css/mystyle.min.css" rel="stylesheet" />
<script src="assets/myjs.min.js"></script>

I set above this correct or not?
How should the correct path be set?
Reply
#5
(04-04-2023, 09:29 AM)baxing Wrote: Hi,

Thank you very much, I tested it and it works.

And if it's the case that I want to link to the css and js files inside the html file, how should I set the path?

<link href="dist/css/mystyle.min.css" rel="stylesheet" />
<script src="assets/myjs.min.js"></script>

I set above this correct or not?
How should the correct path be set?

Hi 

Unfortunately, the only way I could solve this was:
in the ServerController.OnConfig event, my own algorithm modifies the routes in the content of the css/js files. (OnConfig runs only once when ServerController is started.)
The algorithm recognizes the path elements and corrects them.
Reply
#6
Hi there,

there must be some mistake somewhere in your code and/or application.

Any external reference to any file must be set like this:

/assets/myjs.min.js

This will work for *any* project or application type, including ISAPI.

The slash in front of the path means that the file path is relative to the ROOT folder of the application, i.e. the wwwroot folder that should be created under your application folder.

So, inside wwwroot folder you add another folder named assets and then save your file to that folder.

This behavior is explained in the "Absolute and Relative paths" section of this document:

https://docs.atozed.com/Docs.dll/develop...20XIV.html
Reply
#7
Hi,

Previously, I had read the document as you said. I came to understand that identifiers can be used. root-relative path e.g.
/JS/MyLib.js
(where the MyLib.js file is located inside the "wwwroot/JS/" folder)

As I stated in the beginning of this thread specifying like this is no problem (starting with a "/") either within Delphi itself or or refer the path within Html file for building is of type SA (.exe), but it occurs when I build it as ISAPI (.dll) and run it on IIS.

To change the project type, I used the conditional compiler directives ($IFDEFS} from the documentation.

https://docs.atozed.com/docs.dll/deploym...types.html

So please help suggest that. If I set something wrong, where should I go to set it right?
Because I have noticed that running with SA works fine, but only with ISAPI issues.

Thanks
Reply
#8
I'm not exactly sure what is wrong in your case unless you provide me a simple test case showing this error.

There are various ISAPI demos in our github repo and they all work as is in both ISAPI and SA.

I'll post a simple test case here in both ISAPI and SA and you can test them and see how it behaves.
Reply
#9
Hi,

I have made a simple sample project file for you to see clearly. Please use it with both Exe and Dll (ISAPI) you will see the difference as I said.
Note : Please rebuild .exe and .dll by using compiler directive on my test project because I can not attach file size more than 1024 kilobytes.
And 2 attach images , I captured for see different of result while run it with .exe and .dll.

Thanks


Attached Files Thumbnail(s)
       

.zip   TestProject.zip (Size: 500.97 KB / Downloads: 3)
Reply
#10
I see what you mean your template contains the links, you are not adding them using those methods from PageContext or IWForm. Try to reference your files like this:

<script src="../wwwroot/assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

Please notice that I included "../wwwroot" in front of your existing path

IntraWeb template processor always looks for 2 "special" strings in paths of files when processing the template: "../wwwroot" and "../files/"

They both will be replaced when the final HTML is generated. In a simplified way:

../wwwroot -> when your wwwroot folder is under the application folder, IW template processor will replace ../wwwroot by the URL base. In case of ISAPI, it will be something like <Web application alias or name>/<ISAPI dll name>

../files/ -> will be replaced by <URL base>/files/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)