簡體   English   中英

Nodejs每個響應發送多個文件

[英]Nodejs send multiple files per response

我希望每個響應向用戶發送多個文件。 例如,用戶請求索引站點,站點需要一些.png,css等。

用戶只能獲得他需要的所有包。 這個想法。

所以我的想法是,它會以這樣的方式實現:

      res.writeHead(200, {'Content-Type': 'text/html'});

      var content = fs.readFileSync(applicationPath + "index.html");
      res.write(content);
      content = fs.readFileSync(applicationPath + "images/logo.png");
      res.write(content);
      content = fs.readFileSync(applicationPath + "index.css");
      res.write(content);

      res.end();

這有可能嗎? 或者還有其他解決方案嗎?

感謝您的幫助和解答!

你通過說“包”來固定它的一個解決方案。 將文件放入存檔並發送一個文件res.write(archive_content)。 當然,相應地改變內容類型。

如何在此處創建存檔: 使用zlib壓縮多個文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM