ایپلی کیشنز کو اکثر متحرک درخواستوں کو سنبھالنے کے علاوہ جامد فائلوں جیسے JavaScript، تصاویر اور CSS کو پیش کرنے کی ضرورت ہوتی ہے۔ لچکدار ماحول میں ایپس گوگل کلاؤڈ آپشن جیسے کلاؤڈ اسٹوریج سے جامد فائلیں پیش کر سکتی ہیں، انہیں براہ راست پیش کر سکتی ہیں، یا تھرڈ پارٹی مواد کی ترسیل کے نیٹ ورک (CDN) کا استعمال کر سکتی ہیں۔ ## کلاؤڈ اسٹوریج سے فائلیں پیش کرنا Cloud Storage متحرک ویب ایپس کے لیے جامد اثاثوں کی میزبانی کر سکتا ہے۔ اپنی ایپ سے براہ راست خدمت کرنے کے بجائے کلاؤڈ اسٹوریج استعمال کرنے کے فوائد میں شامل ہیں: - کلاؤڈ اسٹوریج بنیادی طور پر مواد کی ترسیل کے نیٹ ورک کے طور پر کام کرتا ہے۔ اس کے لیے کسی خاص ترتیب کی ضرورت نہیں ہے کیونکہ بطور ڈیفالٹ کوئی بھی پڑھنے کے قابل آبجیکٹ کو عالمی کلاؤڈ اسٹوریج نیٹ ورک میں محفوظ کیا جاتا ہے۔ - Cloud Storage میں پیش کرنے والے جامد اثاثوں کو آف لوڈ کرنے سے آپ کی ایپ کا بوجھ کم ہو جائے گا۔ اس بات پر منحصر ہے کہ آپ کے پاس کتنے جامد اثاثے ہیں اور رسائی کی فریکوئنسی، یہ آپ کے ایپ کو چلانے کی لاگت کو ایک قابل ذکر رقم سے کم کر سکتا ہے۔ - مواد تک رسائی کے لیے بینڈوتھ چارجز اکثر کلاؤڈ اسٹوریج کے ساتھ کم ہو سکتے ہیں۔ آپ اپنے اثاثوں کو کلاؤڈ اسٹوریج پر اپ لوڈ کر سکتے ہیں۔ gsutil کمانڈ لائن ٹول یا Cloud Storage API Google کلاؤڈ کلائنٹ لائبریری Cloud Storage کو ایک محاوراتی کلائنٹ فراہم کرتی ہے، تاکہ ایک App Engine ایپ میں Cloud Storage کے ساتھ ڈیٹا کو ذخیرہ اور بازیافت کیا جا سکے۔ کلاؤڈ اسٹوریج بالٹی سے سرونگ کی مثال یہ سادہ مثال کلاؤڈ اسٹوریج بالٹی بناتی ہے اور گوگل کلاؤڈ CLI کا استعمال کرتے ہوئے جامد اثاثے اپ لوڈ کرتی ہے: ایک بالٹی بنائیں۔ اپنی بالٹی کا نام اپنے پروجیکٹ ID کے بعد رکھنا عام ہے، لیکن اس کی ضرورت نہیں ہے۔ بالٹی کا نام عالمی سطح پر منفرد ہونا چاہیے۔ gsutil mb gsyour-bucket-name>بالٹی میں آئٹمز تک پڑھنے کی رسائی دینے کے لیے ACL کو سیٹ کریں۔ gsutil defacl عوامی پڑھا ہوا gsyour-bucket-name>سیٹ کریں۔ اشیاء کو بالٹی میں اپ لوڈ کریں۔ دی rsynccommand عام طور پر اثاثوں کو اپ لوڈ اور اپ ڈیٹ کرنے کا تیز ترین اور آسان طریقہ ہے۔ آپ بھی استعمال کر سکتے ہیں۔ cp gsutil -m rsync -r ./static gsyour-bucket-name>/static اب آپ اپنے جامد اثاثوں تک رسائی حاصل کر سکتے ہیں۔ httpsstorage.googleapis.com//static For more details on how to use Cloud Storage to serve static assets, including how to serve from a custom domain name, refer to How to Host a Static Website Serving files from other Google Cloud services You also have the option of using Cloud CDN or other Google Cloud storage services ## Serving files directly from your app Serving files from your app is typically straightforward, however, there are a couple drawbacks that you should consider: - Requests for static files can use resources that otherwise would be used for dynamic requests - Depending on your configuration, serving files from your app can result in response latency, which can also affect when new instances are created for handling the load Example of serving static files with your app Go In Go, you can use the standard http.FileServer or http.ServeFile to serve files directly from your app // Package static demonstrates a static file handler for App Engine flexible environment. package main import ( "fmt" "net/http" "google.golang.org/appengine" ) func main() { // Serve static files from "static" directory. http.Handlestatic http.FileServer(http.Dir http.HandleFunc homepageHandler) appengine.Main() } const homepage = doctype html> Static Files /main.css">

This is a static file serving examplep>

Static Files /styles.css">

This is a static file serving examplep>

default doctype html html(lang="en") head title Static Files meta(charset='utf-8') link(rel="stylesheet", hrefstatic/main.css") body p This is a static file serving example The stylesheet itself is located at ./public/css, which is served from /static/main.css body { font-family: Verdana, Helvetica, sans-serif; background-color: #CCCCFF; } Other Node.js frameworks, such as Hapi, Koa, and Sails typically support serving static files directly from the application. Refer to their documentation for details on how to configure and use static content PHP The PHP runtime runs nginx to serve your app, which is configured to serve static files in your project directory. You must declare the document root by specifying document_root in your app.yaml file: runtime: php env: flex runtime_config: document_root: web Python Most web frameworks include support for serving static files. In this sample, the app uses Flask's built-in ability to serve files in ./static directory from the /static URL The app includes a view that renders the template. Flask automatically serves everything in the ./static directory without additional configuration import logging from flask import Flask, render_template app = Flaskname @app.route def hello return render_template('index.html') @app.errorhandler(500) def server_error(e): logging.exception('An error occurred during a request returnAn internal error occurred: See logs for full stacktrace. format(e), 500 if __name__ == main # This is used when running locally. Gunicorn is used to run the # application on Google App Engine. See entrypoint in app.yaml. app.run(host='127.0.0.1', port=8080, debug=True) The template rendered by the view includes a stylesheet located at /static/main.css Static FilesFlask automatically makes files in the 'static' directory available via '/static'./main.css">

This is a static file serving examplep>

doctype html html head title Serving Static Files link rel="stylesheet" hrefapplication.css" script srcapplication.js" body p This is a static file serving example The stylesheet is located at ./public/application.css which is served from /application.css body { font-family: Verdana, Helvetica, sans-serif; background-color: #CCCCFF; } Ruby on Rails The Ruby on Rails web framework serves files from the ./public directory by default. Static JavaScript and CSS files can also be generated by the Rails asset pipeline This example app has a layout view that includes all the app's stylesheets: doctype html html head title Serving Static Files = stylesheet_link_tag "application", media: "all" = javascript_include_tag "application" = csrf_meta_tags body = yield The stylesheet itself is a Sass file located at ./app/assets/stylesheets/main.css.sass body font-family: Verdana, Helvetica, sans-serif background-color: #CCCCFF By default, Rails apps do not generate or serve static assets when running in production The Ruby runtime executes rake assets:precompile during deployment to generate static assets and sets the RAILS_SERVE_STATIC_FILES environment variable to enable static file serving in production .NET Hello Static World

This is a static html documentp>