JQ Issues

General discussion about anything related to Ultibo.
pjde
Posts: 410
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

JQ Issues

Postby pjde » Wed Jun 20, 2018 5:05 am

Hi Garry

I am trying to get JQ Mobile to work on an Ultibo HTTP Server.

In order for this to work there are 2 css files of 203kb and 23kb respectiverly and 3 js files of 196kb, 92kb and 2kb respectivly specified within the head of the HTML page.

When I open the html page as a file from my windows machine all is good, but when I serve it from my PI all the styles are lost.

Have you tested serving HTML pages with large css and js files or should I be hunting through my code.

Regards as always

Paul
User avatar
Ultibo
Site Admin
Posts: 2040
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: JQ Issues

Postby Ultibo » Wed Jun 20, 2018 5:38 am

pjde wrote:When I open the html page as a file from my windows machine all is good, but when I serve it from my PI all the styles are lost.

Have you tested serving HTML pages with large css and js files or should I be hunting through my code.

The css and js files should just appear as a URL and the browser should be attempting to fetch each one after it gets the html page.

As long as you have a THTTPFolder object configured that represents the location where these files are being requested then it should work regardless of the type or size of the files involved.

Can you give an outline of the http objects you create in your Ultibo code, that might explain something.

Also, I noticed that the default list of Mime Types provided with the HTTP unit includes css files but doesn't have anything for js, you can register new types on the fly by calling FindHost() on the listener (pass an empty string for the default host) and then calling RegisterMimeType() on the returned THTTPHost object.

From the official list at IANA it looks like it should be application/javascript for a js file.
Ultibo.org | Make something amazing
https://ultibo.org
pjde
Posts: 410
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: JQ Issues

Postby pjde » Wed Jun 20, 2018 6:06 am

I will zip up an example and send it on.
pjde
Posts: 410
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: JQ Issues

Postby pjde » Wed Jun 20, 2018 6:24 am

Hi Garry

Have uploaded my project to date at <URL Deleted>

Let us know when you have a copy as I will delete it off the repo.

Regards

Paul
User avatar
Ultibo
Site Admin
Posts: 2040
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: JQ Issues

Postby Ultibo » Wed Jun 20, 2018 6:37 am

pjde wrote:Let us know when you have a copy as I will delete it off the repo.

Ok got it, let me have a look.
Ultibo.org | Make something amazing
https://ultibo.org
User avatar
Ultibo
Site Admin
Posts: 2040
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: JQ Issues

Postby Ultibo » Wed Jun 20, 2018 7:21 am

pjde wrote:When I open the html page as a file from my windows machine all is good, but when I serve it from my PI all the styles are lost.

The Browser Console in Firefox was reporting that the CSS files were being returned as text/html instead of text/css, your custom class is missing the lines that determine the mime type and add it to the response.

I changed your DoGet function as follows and it works perfectly.

Code: Select all

var
  ...
 
  MimeType:String;
  Extension:String;

begin
  ...
 
      s := 'c:\wwwroot\' + p;
      if FileExists (s) then
        begin
          try
            {Get Extension}
            HTTPPathExtractExtension(s,Extension);
         
            {Get MimeType}
            MimeType:=AHost.ResolveMimeType(Extension);

            {Set Content Type}
            AResponse.SetHeader(HTTP_ENTITY_HEADER_CONTENT_TYPE,MimeType);
           
            f := TFileStream.Create (s, fmOpenRead or fmShareDenyNone);
            aResponse.Version := HTTP_VERSION;
            aResponse.Status := HTTP_STATUS_OK;
            aResponse.Reason := HTTP_REASON_200;
 
  ...
 

Hope that makes sense.

I would encourage you to look at / borrow from the DoGet and DoGetFile file methods of THTTPFolder in the HTTP unit, they handle not only the mime type but also things like modified since, allow cache and HEAD requests. All of which will save your client apps from fetching the css, js and images every time.
Ultibo.org | Make something amazing
https://ultibo.org
pjde
Posts: 410
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: JQ Issues

Postby pjde » Wed Jun 20, 2018 8:37 pm

Thanks once again Garry.

I will take your advice.

As this seems a good fit for Ultibo, I will post a full working demo in the near future.


Regards

Paul

Return to “Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest