【问题标题】:configuring SW-precache webpac plugin: can it work with get in the Url?配置 SW-precache webpac 插件:它可以与 URL 中的 get 一起使用吗?
【发布时间】:2018-03-05 15:35:54
【问题描述】:

现在在我们的网络应用程序中,我们有一条如下所示的路线:

Route::get('/{storeName}','HomeController@mainPage');

并且使用商店的名称,我们加载商店的信息,使用不同的模板,具体取决于商店的专业。我们有几个视图,选择其中一个加载到控制器中:

  class HomeController extends Controller
    {
       public function mainPage($storeName)
      {
       (..... Calls to the DB and other things........)
       return view('homePage/'.$store->template,[store-data])
      }
   }

我们一直在考虑迁移到 Progressive Web App,并且我一直在研究 Service Worker 预缓存。我想知道如何在 dynamicUrlToDependencies 中做类似的事情。

到目前为止,据我了解,它通过传递 url,然后是视图来工作,这个:

module.exports.plugins.push(
    new SWPrecacheWebpackPlugin({
        cacheId: 'pwa',
        filename: 'service-worker.js',
        staticFileGlobs: ['public/**/*.{css,eot,svg,ttf,woff,woff2,js,html}'],
        minify: true,
        stripPrefix: 'public/',
        handleFetch: true,
        dynamicUrlToDependencies: {
            '/': ['resources/views/landing/landing.blade.php'],
            '/planes': ['resources/views/landing/new-precios.blade.php'],
            '/registro': ['resources/views/landing/registro.blade.php'],
            '/politicas-privacidad': ['resources/views/landing/politicas.blade.php'],
            '/articles': ['resources/views/articles.blade.php']
        },
        staticFileGlobsIgnorePatterns: [/\.map$/, /mix-manifest\.json$/, /manifest\.json$/, /service-worker\.js$/],
        runtimeCaching: [
            {
                urlPattern: /^https:\/\/fonts\.googleapis\.com\//,
                handler: 'cacheFirst'
            },
            {
                urlPattern: /^https:\/\/www\.thecocktaildb\.com\/images\/media\/drink\/(\w+)\.jpg/,
                handler: 'cacheFirst'
            }
        ],
        importScripts: ['./js/push_message.js']
    })
);

如何在 dynamicToUrlDependencies 中添加 /{$storeName} 之类的内容?我可以调用视图文件夹,例如 ['resources/views/homePagesTemplates/*.blade.php']?有可能吗?

【问题讨论】:

    标签: laravel-5 service-worker progressive-web-apps


    【解决方案1】:

    我不知道直接的方法,但我希望这会有所帮助..

    1- php artisan make:view 你可以得到这个package,它可以生成视图和抓取视图。

    此外,它还包括扩展其他模板,您将为每种商店准备好这些模板。

    2- 从您的控制器运行 artisan 您可以通过多种方式进行操作,我只是复制粘贴 reference 的 Laravel 代码

    Route::get('/foo', function () {
    $exitCode = Artisan::call('email:send', [
        'user' => 1, '--queue' => 'default'
    ]);
    
    //
    });
    

    所以在你的控制器中将两者结合在一起:

    $store1View = \Artisan::call('make:view'['name' => 'store1Variation', '--extends' => 'stores.store1']);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-30
      • 1970-01-01
      • 1970-01-01
      • 2015-01-23
      相关资源
      最近更新 更多