Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

How to use gzipped zepto.min.js?

I'm working in JS with a 1M ESP-01 and would like to use a compressed zepto.min.js because the code won't fit otherwise. Is this possible? I am not sure how to do custom mimetype or whether that would work.

Comments

  • Personally I deal with low memory in ESP-01 by removing zepto.min.js and using pure JavaScript in my code. In most cases it's not necessary to use external JS libraries. Many things can be done easily in vanilla js, too. For example, I have nicely working version of wifi setup page without zepto. This way you can preserve few KBs

  • Would you be willing to share the wifi setup code?

  • Try to hack mongoose.c, like:

    void mg_serve_http(struct mg_connection nc, struct http_message *hm,
    struct mg_serve_http_opts opts) {
    char *path = NULL;
    struct mg_str *hdr, path_info;
    uint32_t remote_ip = ntohl(
    (uint32_t *) &nc->sa.sin.sin_addr);

    if (mg_check_ip_acl(opts.ip_acl, remote_ip) != 1) {
    /* Not allowed to connect */
    mg_http_send_error(nc, 403, NULL);
    nc->flags |= MG_F_SEND_AND_CLOSE;
    return;
    }

    if MG_ENABLE_HTTP_URL_REWRITES

    if (mg_http_handle_forwarding(nc, hm, &opts)) {
    return;
    }

    if (mg_http_send_port_based_redirect(nc, hm, &opts)) {
    return;
    }

    endif

    if (opts.document_root == NULL) {
    opts.document_root = ".";
    }
    if (opts.per_directory_auth_file == NULL) {
    opts.per_directory_auth_file = ".htpasswd";
    }
    if (opts.enable_directory_listing == NULL) {
    opts.enable_directory_listing = "yes";
    }
    if (opts.cgi_file_pattern == NULL) {
    opts.cgi_file_pattern = ".cgi$|.php$";
    }
    if (opts.ssi_pattern == NULL) {
    opts.ssi_pattern = ".shtml$|.shtm$";
    }
    if (opts.index_files == NULL) {
    opts.index_files = "index.html,index.htm,index.shtml,index.cgi,index.php";
    }
    /* Normalize path - resolve "." and ".." (in-place). /
    if (!mg_normalize_uri_path(&hm->uri, &hm->uri)) {
    mg_http_send_error(nc, 400, NULL);
    return;
    }
    if (mg_uri_to_local_path(hm, &opts, &path, &path_info) == 0) {
    mg_http_send_error(nc, 404, NULL);
    return;
    }
    /
    my code begin /
    opts.custom_mime_types = ".css.gz=text/css,.js.gz=application/javascript";
    if (strcmp(path, "/mini-nord.css.gz") == 0)
    {
    opts.extra_headers = "content-encoding:gzip";
    }
    else if (strcmp(path, "/zepto.js.gz") == 0)
    {
    opts.extra_headers = "content-encoding:gzip";
    }
    else
    {
    opts.extra_headers = NULL;
    }
    /
    my code end */
    mg_send_http_file(nc, path, &path_info, hm, &opts);

    MG_FREE(path);
    path = NULL;

    /* Close connection for non-keep-alive requests */
    if (mg_vcmp(&hm->proto, "HTTP/1.1") != 0 ||
    ((hdr = mg_get_http_header(hm, "Connection")) != NULL &&
    mg_vcmp(hdr, "keep-alive") != 0)) {

    if 0

    nc->flags |= MG_F_SEND_AND_CLOSE;
    

    endif

    }
    }

    zepto.min.js.gz, is so small, and it is handy.

Sign In or Register to comment.